python 在asyncio的事件循环上运行Tornado,包括请求处理程序中的'yield from'支持

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 在asyncio的事件循环上运行Tornado,包括请求处理程序中的'yield from'支持相关的知识,希望对你有一定的参考价值。

import asyncio

import tornado.concurrent
import tornado.ioloop
import tornado.web
import tornado.platform.asyncio
import tornado.httpclient

class ReqHandler(tornado.web.RequestHandler):
  async def get(self):
    self.write("Hello world!\n")
    print("Hej!")
    await asyncio.sleep(2)
    print("Hej igen!")
    res = await tornado.httpclient.AsyncHTTPClient().fetch("http://google.com")
    print(res)
    self.write("Hello test\n")

app = tornado.web.Application([
  (r'/', ReqHandler)
])

if __name__ == '__main__':
  tornado.platform.asyncio.AsyncIOMainLoop().install()
  app.listen(8080)
  asyncio.get_event_loop().run_forever()

以上是关于python 在asyncio的事件循环上运行Tornado,包括请求处理程序中的'yield from'支持的主要内容,如果未能解决你的问题,请参考以下文章