Skip to content

Instantly share code, notes, and snippets.

@qrw
Created April 13, 2012 14:58
Show Gist options
  • Save qrw/2377455 to your computer and use it in GitHub Desktop.
Save qrw/2377455 to your computer and use it in GitHub Desktop.
Define a class with a singleton instance
def singleton(cls):
instances = {}
def getinstance():
if cls not in instances:
instances[cls] = cls()
return instances[cls]
return getinstance
@singleton
class MyClass:
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment