Awaiting and scheduling
Learn in depth →An async function call creates a coroutine. Awaiting or scheduling it arranges execution.
await operation()
asyncio.create_task(operation())
async with asyncio.TaskGroup() as group: ...Example
import inspect
async def fetch():
return 42
coroutine = fetch()
print(inspect.iscoroutine(coroutine))
coroutine.close()Result
True
Watch for: Blocking calls still block an event-loop thread. Use cleanup in finally and normally re-raise cancellation after cleanup. TaskGroup needs Python 3.11+.
Practise this topic →