Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Very weird behavior that's driving me crazy

Reply
Thread Tools

Very weird behavior that's driving me crazy

 
 
Pupeno
Guest
Posts: n/a
 
      08-16-2006
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)
 
Reply With Quote
 
 
 
 
Marc 'BlackJack' Rintsch
Guest
Posts: n/a
 
      08-16-2006
In <44e2c4c3$0$20039$>, 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
 
Reply With Quote
 
 
 
 
Simon Forman
Guest
Posts: n/a
 
      08-16-2006
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

 
Reply With Quote
 
Pupeno
Guest
Posts: n/a
 
      08-16-2006
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)
 
Reply With Quote
 
John Machin
Guest
Posts: n/a
 
      08-16-2006

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<---

 
Reply With Quote
 
Bruno Desthuilliers
Guest
Posts: n/a
 
      08-27-2006
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" ?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
code driving me crazy, any assistance? andyjgw@gmail.com ASP .Net 3 07-01-2005 11:33 AM
SelectedIndex in DropDownList....Please help, this is driving me crazy..... Joe Blanchard via .NET 247 ASP .Net 1 05-15-2005 02:05 PM
Could someone test this? It's driving me crazy. Shapper ASP .Net 0 04-29-2005 05:16 PM
Insert and Variables driving me crazy! Newbie... =?Utf-8?B?VGltOjouLg==?= ASP .Net 6 12-21-2004 09:35 AM
ItemTemplate error driving me crazy William Gower ASP .Net 0 04-23-2004 04:04 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57