473,402 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Very weird behavior that's driving me crazy

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 <pu****@pupeno.com(http://pupeno.com)
Aug 16 '06 #1
5 1694
In <44***********************@newsspool4.arcor-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
Aug 16 '06 #2
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 <pu****@pupeno.com(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

Aug 16 '06 #3
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 <pu****@pupeno.com(http://pupeno.com)
Aug 16 '06 #4

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

Aug 16 '06 #5
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" ?
Aug 27 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Robertb | last post by:
I'm driving myself crazy trying to figure this one out. So much so that I think I'm within walking distance now! The program is written and compiled in Visual Basic 6 with SP5. The OS is...
4
by: dont bother | last post by:
This is really driving me crazy. I have a dictionary feature_vectors{}. I try to sort its keys using #apply sorting on feature_vectors sorted_feature_vector=feature_vectors.keys()...
1
by: Kaneda | last post by:
Hello everyone! I have some weird(?) problems, and I am not quite sure if there are due to my errors or maybe a limitation in the .Net framework. I have a ComboBox I need to fill with the...
0
by: Kaneda | last post by:
Hello everyone! I have some weird(?) problems, and I am not quite sure if there are due to my errors or maybe a limitation in the .Net framework. I have a ComboBox I need to fill with the...
6
by: Calvin Lai | last post by:
Hi all, I have the following code which should work. However, an exception ( InvalidOperationException) was thrown which doesn't make sense to me. line 1: foreach (string name in...
0
by: Jeremy | last post by:
I have written my own URL rewriter, and it was working fine until i moved the re-writing code from App_BeginRequest to App_AuthorizeRequest. Now I get a 404 (file not found) error whenever the...
0
by: Shapper | last post by:
Hello, I have this code in Global.asax: Sub Session_Start(Sender As Object, E As EventArgs) Dim cookie As HttpCookie = Request.Cookies("MyCookie") If Not cookie Is Nothing Then...
1
by: Sa¹o Zagoranski | last post by:
Hi... This is driving me crazy and I really hope I can get an answer... Take a look at the piece of code below (I'm using .net 2.0): try { double pointTime =...
5
by: Todd | last post by:
OK...I have a form that has two text boxes. These two fields are being filled from a file import, which works fine. I am then passing these values into a custom class with both values typed as...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.