Python's asyncio.create_task() has a subtle but critical behavior change in Python 3.12+: tasks created without storing a reference can be silently garbage collected before they ever run. This affects 'fire-and-forget' patterns where background tasks are created without awaiting them. The fix is to maintain a global set of task

4m read timeFrom mkennedy.codes
Post cover image
Table of contents
Why asyncio.create_task loses tasks in Python 3.12+One obvious way to do it

Sort: