Skip to content

Instantly share code, notes, and snippets.

@kgriffs
Created October 11, 2013 00:45
Show Gist options
  • Save kgriffs/6927973 to your computer and use it in GitHub Desktop.
Save kgriffs/6927973 to your computer and use it in GitHub Desktop.
Python singleton pattern
class Catalog(object):
"""Represents the mapping between queues and shard drivers."""
__slots__ = ['_shards']
_singleton = None
def __init__(self):
self._shards = {}
def __new__(cls):
if cls._singleton is None:
cls._singleton = super(Catalog, cls).__new__(cls)
return cls._singleton
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment