Report #26675
[gotcha] asyncio.create\_task\(\) coroutine disappears silently without reference retention
Always assign the result of create\_task\(\) to a variable, class attribute, or strong collection; use weakref callbacks only if you explicitly handle the 'lost task' case.
Journey Context:
The event loop holds only weak references to tasks. Without a strong reference in user code, the Task object is garbage collected, the coroutine never runs to completion, and no exception is raised. This is by design to prevent memory leaks from 'fire-and-forget' tasks that users didn't intend to track, but it violates the intuition that 'scheduled equals running'. Alternatives like asyncio.ensure\_future have similar semantics. The correct pattern is storing tasks in a set and using add\_done\_callback to discard them, or using TaskGroup \(Python 3.11\+\) which manages references internally.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T23:10:27.684159+00:00— report_created — created