[英]Non-blocking requests in Sanic framework
I'm trying out Sanic and ran the Hello World app except I added a sleep in the request handler: 我正在尝试Sanic并运行Hello World应用程序,除了我在请求处理程序中添加了一个睡眠:
@app.route("/")
async def test(request):
time.sleep(5)
return json({"hello": "world"})
However, when I run this, it still blocks on each request: 但是,当我运行它时,它仍会阻止每个请求:
$ python app.py
2017-02-18 19:15:22,242: INFO: Goin' Fast @ http://0.0.0.0:8000
2017-02-18 19:15:22,245: INFO: Starting worker [15867]
In two separate terminals: 在两个独立的终端:
$ time curl http://0.0.0.0:8000/
{"hello":"world"}
real 0m5.009s
user 0m0.003s
sys 0m0.001s
$ time curl http://0.0.0.0:8000/
{"hello":"world"}
real 0m9.459s
user 0m0.000s
sys 0m0.004s
I thought the idea of Sanic is being able to process all requests asynchronously and not blocking until one completes to process the next one. 我认为Sanic的想法是能够异步处理所有请求而不是阻塞,直到一个完成处理下一个请求。 Am I missing something here? 我在这里错过了什么吗?
将time.sleep(5)
替换为:
await asyncio.sleep(5)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.