Skip to content

Commit

Permalink
GHI-#4·Implement·the "Singleton(type)"·class
Browse files Browse the repository at this point in the history
  • Loading branch information
arcticicestudio committed Jan 7, 2017
1 parent b85c0d3 commit 3024154
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions snowsaw/util/singleton.py
Original file line number Diff line number Diff line change
@@ -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]

0 comments on commit 3024154

Please sign in to comment.