This repository has been archived on 2019-12-09. You can view files and clone it, but cannot push or open issues or pull requests.
pacman2/engine/singleton.py

24 lines
654 B
Python

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