singleton.py 217B

123456789
  1. def singleton(cls):
  2. instances = {}
  3. def get_instance(*args, **kwargs):
  4. if cls not in instances:
  5. instances[cls] = cls(*args, **kwargs)
  6. return instances[cls]
  7. return get_instance