Multiple await
s run their targets one after the other, not concurrently
- asyncio
- await
- async
The async
/await
syntax merely enables to run other tasks concurrently. It does not automatically define/create tasks, but executes its statements/expression one after the other.
The user is confused because they have a setup of async
and await
, but things still execute one after the other:
async def main():
await some_async_a()
await some_async_b() # only runs after `some_async_a` completed
The correct approach is to explicitly create tasks for concurrent work. This requires framework specific utilities, such as asyncio.create_task
or asyncio.gather
for asyncio
.