static class variables and module scope

T

The Dark Seraph

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 SingletonWrapper:
__instance = None
def __init__ ( self, user = None, password = None ):
if SingletonWrapper.__instance is None:
SingletonWrapper.__instance = ImplSingletonWrapper ( user, password )
def instance ( self ):
return SingletonWrapper.__instance

In my ImplSingletonWrapper 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 SingletonWrapper().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?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top