Answer the question
In order to leave comments, you need to log in
aio http library. Is it possible to parallelize query processing?
Made a simple web server using aiohttp 3.3 and Python 3.6.5
As planned, the request handler should be asynchronous and handle multiple requests in parallel.
To check, I made two requests to the server at the same time and realized that in fact the parallel processing did not work (see the result below)
What am I doing wrong?
from aiohttp import web
import asyncio
async def handler(request):
print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
await asyncio.sleep(5)
return web.json_response({"ok": 1})
app = web.Application()
app.add_routes([web.view('/', handler)])
web.run_app(app, host='0.0.0.0', port=8080)
Answer the question
In order to leave comments, you need to log in
Surely you open two tabs in the same browser and send requests from them. But neither Google Chrome nor Mozila Firefox will send a second request to the same address until they receive a response to the first one. Even if you run two windows. But IE11 sends two requests at the same time to the same address from the tabs without any problems. Try running two different browsers, or even better, use curl for tests.
Parallelism is not asynchrony.
Parallel execution of tasks means that they are executed simultaneously, well, almost simultaneously.
Asynchronous execution is execution in which the processor can work on another task while the current one is waiting for the completion of a long operation, such as a network transfer, or disk work, for example.
aiohttp asynchronous framework, or am I missing something?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question