Non-blocking requests in the Sanic framework

I tried Sanic and launched the Hello World application, except that I added sleep to the request handler:

@app.route("/") async def test(request): time.sleep(5) return json({"hello": "world"}) 

However, when I run this, it still blocks for every 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 that the idea of ​​Sanic allows you to process all requests asynchronously, rather than blocking it until the next one completes. Did I miss something?

+5
source share
1 answer

Replace time.sleep(5) with:

  await asyncio.sleep(5) 
+9
source

Source: https://habr.com/ru/post/1264391/


All Articles