From 30241545d256eaba2eaa5195d706061b68aa93c0 Mon Sep 17 00:00:00 2001 From: Arctic Ice Studio Date: Sat, 7 Jan 2017 13:52:55 +0100 Subject: [PATCH] =?UTF-8?q?GHI-#4=C2=B7Implement=C2=B7the=20"Singleton(typ?= =?UTF-8?q?e)"=C2=B7class?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- snowsaw/util/singleton.py | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 snowsaw/util/singleton.py diff --git a/snowsaw/util/singleton.py b/snowsaw/util/singleton.py new file mode 100644 index 0000000..3776cb9 --- /dev/null +++ b/snowsaw/util/singleton.py @@ -0,0 +1,7 @@ +class Singleton(type): + _instances = {} + + def __call__(cls, *args, **kwargs): + if cls not in cls._instances: + cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs) + return cls._instances[cls]