Report #17968
[gotcha] asyncio.create\_task exception swallowed silently when task not referenced
Always store the Task object returned by create\_task\(\) in a variable, registry, or use add\_done\_callback to handle exceptions. Never fire-and-forget without a strong reference.
Journey Context:
Python's event loop holds only weak references to tasks. If you don't store the Task object, it may be garbage collected before completion, taking any unhandled exception with it. Even if it completes first, the exception remains trapped until the task is queried via result\(\) or exception\(\). Many developers assume 'fire-and-forget' is safe for background tasks, but this leads to silent failures in production. The pattern is to maintain a strong reference \(set/dict of tasks\) and clean up in done-callbacks.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T06:51:48.556127+00:00— report_created — created