import tornado.ioloop import tornado.web from tornado.concurrent import Future import time from tornado import gen #fututre模块进行异步的请求操作 class MainHandler(tornado.web.RequestHandler): @gen.coroutine def get(self, *args, **kwargs): import time global future future=Future() future.add_done_callback(self.done)#加一个返回值回来,当执行完成的时候,就执行下面的函数部分 yield future def done(self,*args,**kwargs): print('执行完成') self.write('完成') self.finish() class IndexHnadler(tornado.web.RequestHandler): def get(self, *args, **kwargs): future.set_result(None)##设置返回值回来 self.write('index') def run(): application=tornado.web.Application([ (r'/main',MainHandler), (r'/index', IndexHnadler), ]) ##seting配置 application.listen(8000) tornado.ioloop.IOLoop.instance().start() run()