Very weird behavior that's driving me crazy

Discussion in 'Python' started by Pupeno, Aug 16, 2006.

  1. Pupeno

    Pupeno Guest

    Hello,
    I am experiencing a weird behavior that is driving me crazy. I have module
    called Sensors containing, among other things:

    class Manager:
    def getStatus(self):
    print "getStatus(self=%s)" % self
    return {"a": "b", "c": "d"}

    and then I have another module called SensorSingleton that emulates the
    hard-to-code-on-python singleton in this way:

    manager = Manager()
    print "manager=%s" % manager
    def getStatus():
    print "getStatus()"
    return manager.getStatus()

    and then in some other module, I import SensorSingleton and I do, among
    other things:

    print SensorSingleton.getStatus()

    and the output is more or less like this. First, the manager:

    manager: <Sensor.Manager object at 0xb7b9efec>

    ok, then

    Manager.getStatus(self=<Sensor.Manager object at 0xb77cde8c>) =>
    {"a": "b", "c": "d"}
    None

    None is the return of SensorSingleton.getStatus(), now, my questions are:

    - Shouldn't the manager be the same in the first print and the second, that
    is, the id is different, shouldn't it be the same ?
    - What happened with all the output of SensorSingleton.getStatus() ? there's
    no trace of it (but there's output of the method it calls).
    - Why doesn't the SensorSingleton.getStatus() return the return value of
    manager.getStatus(), it's a very straight forward call to it and return it.

    Thank you.
    --
    Pupeno <> (http://pupeno.com)
    Pupeno, Aug 16, 2006
    #1
    1. Advertising

  2. In <44e2c4c3$0$20039$-online.net>, Pupeno wrote:

    > - Shouldn't the manager be the same in the first print and the second, that
    > is, the id is different, shouldn't it be the same ?
    > - What happened with all the output of SensorSingleton.getStatus() ? there's
    > no trace of it (but there's output of the method it calls).
    > - Why doesn't the SensorSingleton.getStatus() return the return value of
    > manager.getStatus(), it's a very straight forward call to it and return it.


    How have you tested this? Is there any chance it was an interactive
    session and you forgot to reload the module after making changes to it?

    Ciao,
    Marc 'BlackJack' Rintsch
    Marc 'BlackJack' Rintsch, Aug 16, 2006
    #2
    1. Advertising

  3. Pupeno

    Simon Forman Guest

    Pupeno wrote:
    > Hello,
    > I am experiencing a weird behavior that is driving me crazy. I have module
    > called Sensors containing, among other things:
    >
    > class Manager:
    > def getStatus(self):
    > print "getStatus(self=%s)" % self
    > return {"a": "b", "c": "d"}
    >
    > and then I have another module called SensorSingleton that emulates the
    > hard-to-code-on-python singleton in this way:
    >
    > manager = Manager()
    > print "manager=%s" % manager
    > def getStatus():
    > print "getStatus()"
    > return manager.getStatus()
    >
    > and then in some other module, I import SensorSingleton and I do, among
    > other things:
    >
    > print SensorSingleton.getStatus()
    >
    > and the output is more or less like this. First, the manager:
    >
    > manager: <Sensor.Manager object at 0xb7b9efec>
    >
    > ok, then
    >
    > Manager.getStatus(self=<Sensor.Manager object at 0xb77cde8c>) =>
    > {"a": "b", "c": "d"}
    > None
    >
    > None is the return of SensorSingleton.getStatus(), now, my questions are:
    >
    > - Shouldn't the manager be the same in the first print and the second, that
    > is, the id is different, shouldn't it be the same ?
    > - What happened with all the output of SensorSingleton.getStatus() ? there's
    > no trace of it (but there's output of the method it calls).
    > - Why doesn't the SensorSingleton.getStatus() return the return value of
    > manager.getStatus(), it's a very straight forward call to it and return it.
    >
    > Thank you.
    > --
    > Pupeno <> (http://pupeno.com)


    The code you posted doesn't match the output you posted. Try coding
    the smallest version of what you're trying to do and post its output.

    Peace,
    ~Simon
    Simon Forman, Aug 16, 2006
    #3
  4. Pupeno

    Pupeno Guest

    Nevermind, it was fixed. Thanks.

    Pupeno wrote:

    > Hello,
    > I am experiencing a weird behavior that is driving me crazy. I have module
    > called Sensors containing, among other things:
    >
    > class Manager:
    > def getStatus(self):
    > print "getStatus(self=%s)" % self
    > return {"a": "b", "c": "d"}
    >
    > and then I have another module called SensorSingleton that emulates the
    > hard-to-code-on-python singleton in this way:
    >
    > manager = Manager()
    > print "manager=%s" % manager
    > def getStatus():
    > print "getStatus()"
    > return manager.getStatus()
    >
    > and then in some other module, I import SensorSingleton and I do, among
    > other things:
    >
    > print SensorSingleton.getStatus()
    >
    > and the output is more or less like this. First, the manager:
    >
    > manager: <Sensor.Manager object at 0xb7b9efec>
    >
    > ok, then
    >
    > Manager.getStatus(self=<Sensor.Manager object at 0xb77cde8c>) =>
    > {"a": "b", "c": "d"}
    > None
    >
    > None is the return of SensorSingleton.getStatus(), now, my questions are:
    >
    > - Shouldn't the manager be the same in the first print and the second,
    > that is, the id is different, shouldn't it be the same ?
    > - What happened with all the output of SensorSingleton.getStatus() ?
    > there's no trace of it (but there's output of the method it calls).
    > - Why doesn't the SensorSingleton.getStatus() return the return value of
    > manager.getStatus(), it's a very straight forward call to it and return
    > it.
    >
    > Thank you.


    --
    Pupeno <> (http://pupeno.com)
    Pupeno, Aug 16, 2006
    #4
  5. Pupeno

    John Machin Guest

    Pupeno wrote:
    > Hello,
    > I am experiencing a weird behavior that is driving me crazy. I have module
    > called Sensors containing, among other things:
    >
    > class Manager:
    > def getStatus(self):
    > print "getStatus(self=%s)" % self
    > return {"a": "b", "c": "d"}
    >
    > and then I have another module called SensorSingleton that emulates the
    > hard-to-code-on-python singleton in this way:
    >
    > manager = Manager()
    > print "manager=%s" % manager
    > def getStatus():
    > print "getStatus()"
    > return manager.getStatus()
    >
    > and then in some other module, I import SensorSingleton and I do, among
    > other things:
    >
    > print SensorSingleton.getStatus()
    >
    > and the output is more or less like this. First, the manager:
    >
    > manager: <Sensor.Manager object at 0xb7b9efec>

    ### Uh-oh. The code should print "manager=", not "manager:"
    >
    > ok, then
    >
    > Manager.getStatus(self=<Sensor.Manager object at 0xb77cde8c>) =>

    ### Uh-oh. The code should print "getStatus(self=blahblahblah" i.e.
    without "Manager." in the front.

    > {"a": "b", "c": "d"}
    > None
    >
    > None is the return of SensorSingleton.getStatus(),

    ### What evidence do you have for that statement?

    now, my questions are:
    >
    > - Shouldn't the manager be the same in the first print and the second, that
    > is, the id is different, shouldn't it be the same ?

    ### Yes.

    > - What happened with all the output of SensorSingleton.getStatus() ? there's
    > no trace of it (but there's output of the method it calls).


    ### All what output? The only expected output is "getStatus()"

    > - Why doesn't the SensorSingleton.getStatus() return the return value of
    > manager.getStatus(), it's a very straight forward call to it and return it.
    >


    If you want help, forget the "more or less" caper -- it's useless. It's
    obvious from the above that the output that you describe can *not* have
    come from the code fragments that you showed.Cut your 3 modules down to
    the bare minimum that still shows the bug. Include copies of those plus
    the exact (copy/paste) results of running the test at the OS
    command-line (I.e. not in an IDE). Do make sure that none of your
    modules are being shadowed or are outdated -- have all 3 in your
    current working directory, and delete all .pyc files before running the
    test.

    What version of Python are you running? 2.3? Which platform?

    Below's what I tried -- it's essentially the same as your code, with a
    bit more output and with lower-case module names and I didn't bother
    with a 2-line calling module. It works as expected.

    HTH,
    John

    C:\junk>python
    Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)]
    on win32
    Type "help", "copyright", "credits" or "license" for more information.
    |>>> import singleton
    [singleton] manager=<sensors.Manager instance at 0x00AF43A0>
    |>>> singleton.getStatus()
    [singleton] entered getStatus()
    [sensors]getStatus(self <sensors.Manager instance at 0x00AF43A0>)
    [singleton] stuff = {'a': 'b', 'c': 'd'}
    {'a': 'b', 'c': 'd'}
    |>>> ^Z

    C:\junk>type sensors.py
    class Manager:
    def getStatus(self):
    print "[sensors]getStatus(self %s)" % self
    return {"a": "b", "c": "d"}

    C:\junk>type singleton.py
    from sensors import Manager
    manager = Manager()
    print "[singleton] manager=%s" % manager
    def getStatus():
    print "[singleton] entered getStatus()"
    stuff = manager.getStatus()
    print "[singleton] stuff =", stuff
    return stuff
    8<---
    John Machin, Aug 16, 2006
    #5
  6. Pupeno a écrit :
    (snip)
    >
    > and then I have another module called SensorSingleton that emulates the
    > hard-to-code-on-python singleton (snip)


    What do you mean "hard to code on python singleton" ?
    Bruno Desthuilliers, Aug 27, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. William Gower

    ItemTemplate error driving me crazy

    William Gower, Apr 23, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    315
    William Gower
    Apr 23, 2004
  2. =?Utf-8?B?VGltOjouLg==?=

    Insert and Variables driving me crazy! Newbie...

    =?Utf-8?B?VGltOjouLg==?=, Dec 20, 2004, in forum: ASP .Net
    Replies:
    6
    Views:
    332
    =?Utf-8?B?VGltOjouLg==?=
    Dec 21, 2004
  3. Shapper
    Replies:
    0
    Views:
    330
    Shapper
    Apr 29, 2005
  4. Joe Blanchard via .NET 247
    Replies:
    1
    Views:
    761
    Eliyahu Goldin
    May 15, 2005
  5. Replies:
    3
    Views:
    428
    Kevin Spencer
    Jul 1, 2005
Loading...

Share This Page