码迷,mamicode.com
首页 > 其他好文 > 详细

Sanic 异步非阻塞

时间:2019-07-03 10:31:29      阅读:109      评论:0      收藏:0      [点我收藏+]

标签:zhang   before   run   span   demo   oop   host   cio   test   

异步非阻塞

# 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 异步非阻塞

标签:zhang   before   run   span   demo   oop   host   cio   test   

原文地址:https://www.cnblogs.com/wangyuxing/p/11124716.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!