473,799 Members | 3,147 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

static class variables and module scope

I have a singleton object that works perfectly from inside my main .py
file. However, when I want to access the object that backs the
singleton from another file ( either from an execfile() or thru my
telnet listener ), it appears the underlying object is reset to null,
resulting in a duplicate object being created.

I figure I am doing something painfully stupid, but for the life of me,
I can't see it.

Here is my singleton wrapper:

class SingletonWrappe r:
__instance = None
def __init__ ( self, user = None, password = None ):
if SingletonWrappe r.__instance is None:
SingletonWrappe r.__instance = ImplSingletonWr apper ( user, password )
def instance ( self ):
return SingletonWrappe r.__instance

In my ImplSingletonWr apper class, I print out that I am creating a new
object when its constructor is called. Inside the owner file, it is
only called once , but if I do SingletonWrappe r().instance() from
anohter module, it makes a new object, and id() reports different ids.

I banged my head against this yesterday, and today doesn't seem to be
going any better, any ideas out there?

--
ch***@acheris.n et | Fight Censorship, Boycott Wal-Mart
Now is the winter of your discontent! - Stewie
Jul 18 '05 #1
0 1216

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

Similar topics

3
3937
by: Datta Patil | last post by:
Hi , #include<stdio.h> func(static int k) /* point2 : why this is not giving error */ { int i = 10 ; // static int j = &i ; /* point 1: this will give compile time error */ return k; } /* in above case where is variable k and j mapped in memory layout ? */
2
1439
by: JackRazz | last post by:
I'm trying to serialize a class using the binary formatter without serializing the 'static pastFirstCall as Boolean' variable. Normally private (module-scope) variables are serialized unless the <NonSerialized> attribute is used. Public Function NextMessageNo() As Integer <NonSerialized()> Static pastFirstCall As Boolean = False 'This is being Serialized!!!!!!!!!! If Not pastFirstCall Then mNextMessageNumber =...
2
903
by: JackRazz | last post by:
I'm trying to serialize a class using the binary formatter without serializing the 'static pastFirstCall as Boolean' variable. Normally private (module-scope) variables are serialized unless the <NonSerialized> attribute is used. Public Function NextMessageNo() As Integer <NonSerialized()> Static pastFirstCall As Boolean = False 'This is being Serialized!!!!!!!!!! If Not pastFirstCall Then mNextMessageNumber =...
9
8662
by: CDMAPoster | last post by:
About a year ago there was a thread about the use of global variables in A97: http://groups.google.com/group/comp.databases.ms-access/browse_frm/thread/fedc837a5aeb6157 Best Practices by Kang Su Gatlin, casual mention was made about using static variables as an alternative to using global variables. This caused me to think of the following: '-----Begin module code
2
3778
by: Nagrik | last post by:
Dear Group, The book of Bjarne Stroustrup in chapter 5.4.4 says the following "The word static is one of the most overused words in C and C++. For static data members it has both of the common meanings: static as in "statically allocated" as opposed to on the stack or on the free store and static as in "with restricted visibility" as opposed to with external linkage. For member functions, static has the second meaning."
0
9688
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10491
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10268
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10247
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10031
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6809
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5593
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4146
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.