只需使用
tornado.ioloop.IOLoop.instance()
。它为您的平台选择最佳IOLoop。
if __name__ == "__main__":
application.listen(8888)
ioloop = tornado.ioloop.IOLoop.instance()
print ioloop # prints <tornado.platform.epoll.EPollIOLoop object at ..>
ioloop.start()
你应该打电话
self.finish()
如果您使用
asynchronous
装饰师:
如果给定了这个decorator,则当
方法返回。由请求处理程序调用
self.finish()
以完成HTTP请求。如果没有这个装饰器,请求是
当get()或post()方法返回时自动完成。
class MainHandler(tornado.web.RequestHandler):
@web.asynchronous
@gen.engine
def get(self):
self.write("Hello, world")
self.finish()