Skip to content

Instantly share code, notes, and snippets.

@mcihad
Created February 22, 2016 15:37
Show Gist options
  • Save mcihad/0c87962ea76c4c82822e to your computer and use it in GitHub Desktop.
Save mcihad/0c87962ea76c4c82822e to your computer and use it in GitHub Desktop.
def singleton(class_):
instances = {}
def getinstance(*args, **kwargs):
if class_ not in instances:
instances[class_] = class_(*args, **kwargs)
return instances[class_]
return getinstance
@singleton
class MyClass(BaseClass):
pass
#http://stackoverflow.com/questions/6760685/creating-a-singleton-in-python
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment