![](/img/trans.png)
[英]Why is 'tornado.ioloop.IOLoop.instance().start()' giving me an error?
[英]how does Tornado.ioloop.IOloop.start function work
在Tornado.ioloop.IOloop.start中,只有一行代碼:
raise NotImplementedError()
我想知道以下代碼之后會發生什么
app.listen(8888)
tornado.ioloop.IOLoop.instance().start()
謝謝。
實際上並未使用class IOLoop(Configurable)
。 它只是一個基類。 Tornado將為其選擇一個適當的子類作為默認IOLoop
。 有這樣做的類方法:
@classmethod
def configurable_default(cls):
if hasattr(select, "epoll"):
from tornado.platform.epoll import EPollIOLoop
return EPollIOLoop
if hasattr(select, "kqueue"):
# Python 2.6+ on BSD or Mac
from tornado.platform.kqueue import KQueueIOLoop
return KQueueIOLoop
from tornado.platform.select import SelectIOLoop
return SelectIOLoop
實現細節有點瑣碎。 首先在tornado.util
有一個class Configurable(object)
。 簡單來說,它將使用configurable_default
進行自我配置。 如上所述,我們的IOLoop
是Configurable
的子類,並使用其自己的configurable_default
選擇適當的IOLoop子類,該子類具有start
功能和其他所有功能的有效實現。
在Linux上,實際上執行PollIOLoop.start
方法。 它的實現在這里:
https://github.com/tornadoweb/tornado/blob/master/tornado/ioloop.py#L705
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.