Bases: object
This class allows Singleton objects The __new__ method is overriden to force Singleton behaviour. The Singleton is created for the lowest subclass. Usage:
from taurus.core.util.singleton import Singleton
class MyManager(Singleton):
def init(self, *args, **kwargs):
print "Singleton initialization"
command line:
>>> manager1 = MyManager()
Singleton initialization
>>> manager2 = MyManager()
>>> print(manager1,manager2)
<__main__.MyManager object at 0x9c2a0ec>
<__main__.MyManager object at 0x9c2a0ec>
Notice that the two instances of manager point to the same object even though you tried to construct two instances of MyManager.
Warning
although __new__ is overriden __init__ is still being called for each instance=Singleton()