yidishui111
yidishui111
2015-01-27 11:02

python tornado4.0.2 异步问题

  • python
  • 异步
  • 请求

用tornado时,每个请求sleep5秒,异步的方式,但是从浏览器测试没有出现异步的效果,哪位大侠知道呢

class IndexHandler(tornado.web.RequestHandler):
@tornado.web.asynchronous
@tornado.gen.coroutine
def get(self):
print("begin")
#yield tornado.gen.Task(tornado.ioloop.IOLoop.instance().add_timeout, time.time() + 5)
yield gen.Task(IOLoop.instance().add_timeout, IOLoop.instance().time() + 5)
¦ print("after")
¦ greeting = self.get_argument('greeting', 'Hello')
¦ self.write(greeting + ', friendly user!')
¦ self.finish()

        if __name__ == "__main__":
                tornado.options.parse_command_line()
                app = tornado.web.Application(handlers=[(r"/", IndexHandler)])
                http_server = tornado.httpserver.HTTPServer(app)
                http_server.listen(options.port)
                tornado.ioloop.IOLoop.instance().start()
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答

为你推荐

换一换