jhao преди 6 години
родител
ревизия
a3e1e34e57
променени са 2 файла, в които са добавени 39 реда и са изтрити 0 реда
  1. 26 0
      Util/singleton.py
  2. 13 0
      util/singleton.py

+ 26 - 0
Util/singleton.py

@@ -0,0 +1,26 @@
+# -*- coding: utf-8 -*-
+"""
+-------------------------------------------------
+   File Name:     singleton
+   Description :
+   Author :        JHao
+   date:          2016/12/3
+-------------------------------------------------
+   Change Activity:
+                   2016/12/3:
+-------------------------------------------------
+"""
+__author__ = 'JHao'
+
+
+class Singleton(type):
+    """
+    Singleton Metaclass
+    """
+
+    _inst = {}
+
+    def __call__(cls, *args, **kwargs):
+        if cls not in cls._inst:
+            cls._inst[cls] = super(Singleton, cls).__call__(*args)
+        return cls._inst[cls]

+ 13 - 0
util/singleton.py

@@ -0,0 +1,13 @@
+# -*- coding: utf-8 -*-
+"""
+-------------------------------------------------
+   File Name:     singleton
+   Description :
+   Author :        JHao
+   date:          2020/6/22
+-------------------------------------------------
+   Change Activity:
+                   2020/6/22:
+-------------------------------------------------
+"""
+__author__ = 'JHao'