class Singleton(type):
def __init__(cls, name, bases, dict):
super(Singleton, cls).__init__(name, bases, dict)
cls.instance = None
def __call__(cls, *args, **kw):
if cls.instance is None:
cls.instance = super(Singleton, cls).\
__call__(*args, **kw)
return cls.instance
# class Singleton():
# instance = None
# def __init__(self):
# self.__class__.instance = self
# def get_instance():
# if self.__class__.instance == None:
# raise RuntimeError('Server has not been initialized.')
# else:
# return self.__class__.instance