Quellcode durchsuchen

[add] singleton.py

jhao vor 6 Jahren
Ursprung
Commit
a3e1e34e57
2 geänderte Dateien mit 39 neuen und 0 gelöschten Zeilen
  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'