import threading class Singleton(object): INSTANCE = None lock = threading.RLock() def __new__(cls): cls.lock.acquire() if cls.INSTANCE is None: cls.INSTANCE = super(Singleton, cls).__new__(cls) cls.lock.release() return cls.INSTANCE if __name__ == '__main__': a = Singleton() b = Singleton() print id(a) assert id(a) == id(b)