標籤:tornado.ioloop.ioloop.instance().start()調用了那個start()
我們來分析一下tornado.ioloop.IOLoop.instance().start(),學習了tornado後,當啟動服務的時候,我一直有一個疑惑,我們看一下源碼,IOLoop類中instance()是一個單例模式返回IOLoop執行個體函數
@staticmethod def instance(): """Returns a global `IOLoop` instance. Most applications have a single, global `IOLoop` running on the main thread. Use this method to get this instance from another thread. To get the current thread‘s `IOLoop`, use `current()`. """ if not hasattr(IOLoop, "_instance"): with IOLoop._instance_lock: if not hasattr(IOLoop, "_instance"): # New instance after double check IOLoop._instance = IOLoop() return IOLoop._instance
然後我們再看一下IOloop類的start()函數
def start(self): """Starts the I/O loop. The loop will run until one of the callbacks calls `stop()`, which will make the loop stop after the current event iteration completes. """ raise NotImplementedError()
本文出自 “lpj24” 部落格,請務必保留此出處http://6167018.blog.51cto.com/6157018/1532899