singleton.py 605 B

1234567891011121314151617181920212223242526
  1. # -*- coding: utf-8 -*-
  2. """
  3. -------------------------------------------------
  4. File Name: singleton
  5. Description :
  6. Author : JHao
  7. date: 2016/12/3
  8. -------------------------------------------------
  9. Change Activity:
  10. 2016/12/3:
  11. -------------------------------------------------
  12. """
  13. __author__ = 'JHao'
  14. class Singleton(type):
  15. """
  16. Singleton Metaclass
  17. """
  18. _inst = {}
  19. def __call__(cls, *args, **kwargs):
  20. if cls not in cls._inst:
  21. cls._inst[cls] = super(Singleton, cls).__call__(*args)
  22. return cls._inst[cls]