Async Tasks
examples/async/async_task.py
import asyncio async def answer(): print("start to answer") return 42 async def main(): a_task = asyncio.create_task(answer()) print(a_task) await asyncio.sleep(0) print('before await for task') result = await a_task print(f"result is {result} after await") asyncio.run(main())
<Task pending name='Task-2' coro=<answer() running at async_task.py:3>> start to answer before await for task result is 42 after await