singleton.py 287 B

12345678910
  1. class Singleton:
  2. _instances = {}
  3. def __init__(self, cls):
  4. self._cls = cls
  5. def __call__(self, *args, **kwargs):
  6. if self._cls not in self._instances:
  7. self._instances[self._cls] = self._cls(*args, **kwargs)
  8. return self._instances[self._cls]