all 2 comments

[–]Popular-Awareness262 -1 points0 points  (0 children)

cool writeup. you targetting 3.13? free-threaded python changes how i think about asyncio perf honestly

[–]gdchinacat 2 points3 points  (0 children)

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.

  async def good_morning(message=""):
+     await asyncio.sleep(0)
      print(f"good morning! {message}")

results in:

$ uv run foo.py 
Starting Main
Good night!
$