Skip to content

Instantly share code, notes, and snippets.

@paulofreitas
Created December 17, 2018 01:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulofreitas/7aca08c0a1e6723f2ea5fb4336767dcd to your computer and use it in GitHub Desktop.
Save paulofreitas/7aca08c0a1e6723f2ea5fb4336767dcd to your computer and use it in GitHub Desktop.
class Singleton(type):
_instances = {}
def __call__(cls, *args, **kwargs):
key = (cls, args, str(kwargs))
if key not in cls._instances:
cls._instances[key] = super(Singleton, cls).__call__(*args, **kwargs)
return cls._instances[key]
class Sample(object, metaclass=Singleton):
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment