CKTIS / Python
Keyword await
Inside a coroutine or asynchronous generator, obtain the result or exception of an awaitable.
Version: Python 3.14; repository image, production runtime not attested
Syntax
result = await awaitableInside a coroutine or asynchronous generator, obtain the result or exception of an awaitable.
A ready result need not suspend, while a pending operation can give the event loop control. A completed coroutine object cannot be awaited again.
Calling a coroutine function again creates a fresh coroutine.
Examples
import asyncio
async def job():
await asyncio.sleep(0)
return 7
async def run():
obj = job()
print(await obj)
try:
await obj
except RuntimeError as error:
print(type(error).__name__)
asyncio.run(run())
async def stream():
yield await job()
async def check():
assert [n async for n in stream()] == [7]
asyncio.run(check())
Result
7 RuntimeError
Calling a coroutine function again creates a fresh coroutine.