Skip to content

Instantly share code, notes, and snippets.

@guihao-liang
Created June 25, 2020 17:03
Show Gist options
  • Select an option

  • Save guihao-liang/7f2f58eb426b8d23bdff541dbbfa43d2 to your computer and use it in GitHub Desktop.

Select an option

Save guihao-liang/7f2f58eb426b8d23bdff541dbbfa43d2 to your computer and use it in GitHub Desktop.
pythonic design patterns
class Example(object):
"""A singleton not thread safe
"""
_instance = None
@classmethod
def instance(cls):
if cls._instance is None:
cls._instance = cls.__new__(cls)
cls._instance._attrs = []
return cls._instance
def __init__(self):
raise RuntimeError('This is a singleton, call instance() instead.'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment