Question

i am trying to make epoll work on tornado

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()

but when i start the program and visit the url localhost:8888/ it didn't return anything. is that my system didn't meet the requirement?my linux version was Ubuntu 12.04.1 LTS.

Was it helpful?

Solution

Just use tornado.ioloop.IOLoop.instance(). It choose best IOLoop for your platform.

if __name__ == "__main__":
    application.listen(8888)
    ioloop = tornado.ioloop.IOLoop.instance()
    print ioloop # prints  <tornado.platform.epoll.EPollIOLoop object at ..>
    ioloop.start()

You should call self.finish() if you use asynchronous decorator:

If this decorator is given, the response is not finished when the method returns. It is up to the request handler to call self.finish() to finish the HTTP request. Without this decorator, the request is automatically finished when the get() or post() method returns.

class MainHandler(tornado.web.RequestHandler):
    @web.asynchronous
    @gen.engine    
    def get(self):
        self.write("Hello, world")
        self.finish()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top