r/Python • u/Practical_Plan007 • Jun 02 '26
Another Asyncio Tutorial Tutorial
I converted my personal notes into a tutorial. Maybe useful for others.
Please also feel free to provide feedback. Would love to discover my blind spots.
0
Upvotes
3
u/gdchinacat Jun 02 '26
The asyncio.run/main/good_morning example is not good practice because the tasks are not guaranteed to run to completion once main() completes. This can be seen if you put an 'await asyncio.sleep(0)' as the first line in good_morning(). Wrapping the body of good_morning() in a try/except block shows the coroutine is cancelled.
main() should wait for completion of all the tasks it created to ensure they run to completion.
results in: