class TOLoop:@staticmethoddef instance ():"""Returns a global `IOLoop` instance.Most applications have a single, global `IOLoop` running on themain thread. Use this method to get this instance fromanother thread. To get the current thread's `IOLoop`, use `current()`."""if not hasattr ( IOLoop , "_instance" ): //避免无意义的锁定, 因为大部分调用时只是简单的返回已经创建的_instancewith IOLoop . _instance_lock :if not hasattr ( IOLoop , "_instance" ):# New instance after double checkIOLoop . _instance = IOLoop ()return IOLoop . _instance
Borg is good for SUBCLASS
class Borg:
__shared_state = {}
# init internal state variables here
__register = {}
def __init__(self):
self.__dict__ = self.__shared_state
if not self.__register:
self._init_default_register()
for example
class SubBorg(Borg):
pass