Created
October 11, 2013 00:45
-
-
Save kgriffs/6927973 to your computer and use it in GitHub Desktop.
Python singleton pattern
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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