I'm using the following code to instantiate a singleton in python:
class Singleton(type):
def __init__(cls, name, bases, dic):
super(Singleton, cls).__init__(name, bases, dic)
cls.instance = None
def __call__(cls, *args, **kwargs):
if cls.instance is None:
if DEBUG:
print("Creating NEW Orchestrator instance")
else:
if DEBUG:
print("Using EXISTING Orchestrator instance")
cls.instance = super(Singleton, cls).__call__(*args, **kwargs)
return cls.instance
The init looks like this:
def __init__(self, arg=None):
...
When I instantiate the object it doesn't seem to accept the argument:
Obj = Object("parameter")
arg does not equal "parameter". It is None.
I thought this was the purpose in passing *args to the call. How would I pass an argument upon first instantiating a singleton?
Objectclass. I am assuming this is usingSingletonas its metaclass?__new__, not__init__?__call__method -- the first else statement and its block should probably be "outdented" one level.if debug: ... else: if debug: ...- what?