Fire-and-forget task (ARCH2021)
Key python.async.fire-and-forget-task · Severity warning · Category async
Leaving a coroutine or task as a bare expression statement without awaiting, assigning, or returning it loses exceptions and makes ordering undefined. The task runs unsupervised in the background and its failures vanish silently.
Incorrect
Section titled “Incorrect”import asyncio
async def handle(): asyncio.create_task(send_email()) # unawaited, errors are lost return "ok"Correct
Section titled “Correct”import asyncio
async def handle(): task = asyncio.create_task(send_email()) await task return "ok"Await the created task, return it, or manage its lifetime and exceptions with a TaskGroup.