I'm trying to understand how asyncio
allows for multiple IO waits to happen in parallel. It is often said that asyncio
enables concurrency, but not parallelism. From what I understand, this is true for Python code as such, but something must be happening in parallel, otherwise the execution time would still be the sum of its parts? That something is presumably waiting for IO.
The generic example uses sleep
- we have two tasks sleeping, at least conceptually, in parallel.
Other tutorials use aiohttp
to run multiple HTTP requests concurrently, presumably with many of them waiting on their data in parallel. But how is it done? How is a (blocking) read initiated and then control relinquished until it's done? I imagine the actual parallelism happens at the OS level, or maybe some underying C library, but I don't know how to express that in Python.
What happens under the hood (e.g. in aiohttp
)?