#encoding=utf8
import threading
class Singleton(object):
"""
***Python实现单例模式(类似Tronado.IOLoop)***
关键点:**双重判断,二层加锁**,各种语言实现方式都类似
"""
_instance_lock = threading.Lock()
@staticmethod
def instance():
if not hasattr(Singleton, '_instance'):
with Singleton._instance_lock:
if not hasattr(Singleton, '_instance'):
Singleton._instance = Singleton()
return Singleton._instance