Where is the asynchronism of Sanic?

has the following code. In my expectation, using two browser windows (A _ Magi B window) to access http://127.0.0.1:8000 at the same time, the total time to wait for the two pages to load should be close to 10 seconds, but it actually takes 20 seconds, A window loads in 10 seconds, B window loads in 10 seconds.

import asyncio
from sanic import Sanic, response

app = Sanic(__name__)


@app.route("/")
async def test(request):
    await asyncio.sleep(10)  -sharp  10 
    return response.json({"test": True})


if __name__ == "__main__":
    app.run(port=8000, debug=True)
Aug.16,2021
The

code is fine, and opening two identical links with Chrome will cause the other one to be loaded after it has been loaded. So use tools such as ab when testing.

Menu