Asyncio notes
Contents
single thread cooperative multitasking
test 2
Awaitable
Coroutine
|
|
A coroutine execution returns a coroutine object. Simply calling a coroutine will not schedule it to be executed
Coroutine can be awaited and it makes the execution synchronous from the caller perspective
Can be run with :
await
asyncio.run()
asyncio.create_task()
to run coroutines concurrently as asyncio tasks
Task
Tasks are used to schedule coroutines concurrently
|
|
Future
A
Future
is a special low-level awaitableFuture objects in asyncio are needed to allow callback-based code to be used with async/await.
Running an asyncio program
- Using
asyncio.run(coroutine())
- Creates an event loop and manages awaiting and closing the pool
- Only one pool allowed at the same time by thread