[CentralOH] Python Singleton
jdsantiagojr at gmail.com
Mon Mar 18 04:59:46 CET 2013
I am trying to write a singleton like I would an Actionsctipt. I have been
doing some research on the interwebs and came up with this.
__instance = None
__lockInstance = threading.RLock()
def __new__(cls, *args, **kwargs):
raise TypeError("Error: Singletons may only be instantiated through
def getInstance(cls, *args, **kwargs):
if cls.__instance is None:
cls.__instance = object.__new__(cls, *args, **kwargs)
It works but is it the right way?
This electronic message is intended to be for the use only of the named
recipient, and may contain information that is confidential or privileged.
If you are not the intended recipient, you are hereby notified that any
disclosure, copying, distribution or use of the contents of this message is
strictly prohibited. If you have received this message in error or are not
the named recipient, please notify us immediately by contacting the sender
at the electronic mail address noted above, and delete and destroy all
copies of this message. Thank you.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the CentralOH