What this thread does
The problem
Two common async Python failures:
1. RuntimeWarning: coroutine 'x' was never awaited, and the function body never ran. 2. A FastAPI app that works for one user and crawls under several, because an async def endpoint calls blocking code.
Agents mix these up by adding async to everything, or by wrapping calls in asyncio.run inside a running loop.
Demand
The Stack Overflow questions "Learning asyncio: 'coroutine was never awaited' warning error" and "Fire and forget python async/await" discuss these failures. The accepted answer for the first explains that calling an async def function returns a coroutine object and the code inside runs only when you await it or schedule it as a task.
What the FastAPI docs say
Concurrency and async / await:
- If the library you call supports
await, useasync def; if it does not (the docs say most database libraries at the time of writing), use plaindef; if unsure, usedef. defpath operations anddefdependencies run in an external threadpool, so they do not block the event loop.async defones run on the event loop itself.async defwithout anyawaitis fine when nothing external is waited on.- Your own helper functions are not changed by FastAPI: calling an
async defhelper still needsawait.
So: a requests.get(...) or a synchronous ORM query inside async def blocks the event loop handling those requests. Either make the endpoint def, or use an async client (httpx.AsyncClient, an async driver) with await.
Fixes
- Missing
await: putawaitbefore the call, orasyncio.create_task(...)and keep a reference if you really want fire-and-forget. - Blocking call in
async def: switch todef, an async library, or run it in a thread withasyncio.to_thread(...). - Do not call
asyncio.run()inside code that is already inside an event loop (FastAPI endpoints, notebooks).
How to describe it to your agent
The warning says a coroutine was never awaited in <file>. Find every call to an async def function without await or create_task. Then list every async def endpoint that calls blocking I/O (requests, sync DB driver, time.sleep, file reads of big files) and either change it to def, use an async library, or wrap it with asyncio.to_thread. Use async def even without await when the endpoint waits on nothing external.
Mistakes to check
time.sleepinsideasync def(useawait asyncio.sleep).- Forgetting to keep the task reference from
create_task; the task may be garbage collected. - Using plain
withinstead ofasync withfor aiohttp sessions (a TypeError that agents often misread).
Limits
I did not reproduce this myself. The causes and fixes come from the official pages and the Stack Overflow answers named above.
Sources
Primary source, opened 18 October 2026: FastAPI Concurrency and async / await.
- Confirms: use
async defwhen the library supportsawait, plaindefotherwise, anddefwhen unsure (most database libraries are in the second group);defpath operations and dependencies run in an external threadpool;async defwithoutawaitis fine when the code waits on nothing external; your ownasync defhelpers still needawait. - Adds: the page does not name
requestsor a synchronous ORM; the claim that they block the loop insideasync defis an inference from its blocking-I/O guidance. Plaindefhelpers you call yourself are not sent to the threadpool, only functions FastAPI calls. For trivial compute-only code the page saysasync defis usually the better choice. - Also checked on 2026-11-15: Python's Coroutines and tasks and Runners for the
asyncio.to_thread,create_taskandasyncio.runadvice; aiohttp's client source for theasync withrequirement.
Started from a post by @Sebastian Ramirez (FastAPI), packaged by the editor. Original post