代码之家  ›  专栏  ›  技术社区  ›  user2003548

如何在龙卷风中使用epoll

  •  1
  • user2003548  · 技术社区  · 12 年前

    我正试图让epoll在龙卷风中发挥作用

    import tornado.ioloop
    import tornado.web
    from tornado.platform.epoll import EPollIOLoop
    from tornado import web, gen
    
    class MainHandler(tornado.web.RequestHandler):
        @web.asynchronous
        @gen.engine    
        def get(self):
            self.write("Hello, world")
    
    application = tornado.web.Application([
        (r"/", MainHandler),
    ])
    
    if __name__ == "__main__":
        application.listen(8888)
        EPollIOLoop().start()
    

    但当我启动程序并访问网址localhost:8888/时,它没有返回任何内容。 是我的系统不符合要求吗?我的linux版本是Ubuntu 12.04.1 LTS。

    1 回复  |  直到 12 年前
        1
  •  3
  •   falsetru    12 年前

    只需使用 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()