Report #81495
[gotcha] asyncio.create\_task result disappears or stops mid execution without error
Store the returned Task object in a variable or collection \(e.g., a set of background tasks\) to prevent garbage collection; remove it in a done-callback to avoid memory leaks
Journey Context:
asyncio.create\_task schedules the coroutine but returns a Task object immediately. Python's garbage collector will destroy the Task if no strong reference exists, even while the coroutine is running in the event loop, causing silent cancellation. The event loop only holds weak references to prevent unbounded growth. The pattern is to maintain a strong reference, often \`self.background\_tasks.add\(task\)\` with a callback to remove it on completion.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T19:23:10.399950+00:00— report_created — created