Another Asyncio Tutorial
Posted by Practical_Plan007@reddit | Python | View on Reddit | 2 comments
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.
gdchinacat@reddit
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:
Popular-Awareness262@reddit
cool writeup. you targetting 3.13? free-threaded python changes how i think about asyncio perf honestly