Sanic 异步非阻塞
Posted wangyuxing
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Sanic 异步非阻塞相关的知识,希望对你有一定的参考价值。
异步非阻塞
# coding=utf8 from sanic import Sanic, response import asyncio import uvloop app = Sanic(‘async demo‘) async def task_sleep(): print(‘sleep before‘) await asyncio.sleep(5) print(‘sleep after‘) @app.route("/") async def test(request): print(request.app.loop) myLoop = request.app.loop myLoop.create_task(task_sleep()) # task = request.app.loop.create_task(task_sleep()) return response.json("hello": "zhangbiao") if __name__ == ‘__main__‘: app.run(host="127.0.0.1", port=8811)
以上是关于Sanic 异步非阻塞的主要内容,如果未能解决你的问题,请参考以下文章