Report #30062
[gotcha] Silent disappearance of asyncio tasks due to garbage collection
Always assign the result of \`asyncio.create\_task\(\)\` to a variable with a lifetime extending to task completion, or store it in a persistent collection with a done-callback cleanup pattern.
Journey Context:
Before Python 3.7, the event loop held strong references to all tasks. In 3.7\+, it maintains a \`WeakSet\` to prevent reference cycles. If the caller drops the reference \(e.g., \`asyncio.create\_task\(coro\(\)\)\` without assignment\), garbage collection may reclaim the Task mid-execution, causing the coroutine to vanish silently without completing or raising CancelledError. This particularly affects fire-and-forget patterns and background tasks spawned inside methods.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T04:50:54.540638+00:00— report_created — created