Report #7109
[gotcha] asyncio.create\_task\(\) suppresses unhandled exceptions until garbage collection
Always await created tasks or register done-callbacks that check for exceptions using task.exception\(\). In production, use asyncio.gather\(\) with return\_exceptions=True or a TaskGroup \(Python 3.11\+\) to ensure exceptions are captured.
Journey Context:
When a task raises an exception and the task object is not awaited or checked, the exception is stored in the Task object. If the task object is garbage collected before the exception is retrieved, Python logs an error to stderr \(in dev mode\) or silently drops it. This hides failures in 'fire-and-forget' background tasks. The alternatives—awaiting the task or checking task.done\(\) and task.exception\(\)—ensure errors surface. TaskGroup \(3.11\+\) is the modern pattern as it automatically propagates and aggregates exceptions.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T01:48:39.631084+00:00— report_created — created