Full Byte Developer.

Python async def is lazy until you await

Calling async def returns a coroutine object. Nothing runs until you await it or schedule it on the event loop.

Published here , updated · 3 sources

Calling an async def function does not run its body. Per the language reference, async def always defines a coroutine function, even when the body has no await, and the call returns a coroutine object that stays idle until you await it or schedule it on the event loop [1][2].

Call the function and print the type

Build a tiny coroutine, call it once without awaiting, then finish it with asyncio.run [2]:

async_lazy.py
import asyncio

async def work():
    print("body ran")
    return 42

coro = work()
print(type(coro).__name__)
print(asyncio.run(coro))
bash
python3 async_lazy.py

Captured output:

text
coroutine
body ran
42

The first line is the type name of the object you built. The print inside work appears only after asyncio.run drives the coroutine to completion [2]. If you stop after work() and never await, CPython later emits RuntimeWarning: coroutine was never awaited when the object is collected [2].

See call versus await on one diagram

async def work(): ... 1. call work() body still idle 2. coroutine object type name: coroutine 3. await / run body prints Discarding the object without await leaves the body untouched and later trips RuntimeWarning: coroutine was never awaited [2]

The call builds an awaitable; only await, create_task, or asyncio.run moves the body forward.

Drop a coroutine on purpose and read the warning

never_awaited.py
import asyncio
import warnings

warnings.simplefilter("always")

async def boom():
    print("should not print without await")

async def main():
    boom()

asyncio.run(main())
bash
python3 never_awaited.py

Captured output (warning text may wrap):

text
... RuntimeWarning: coroutine 'boom' was never awaited
RuntimeWarning: Enable tracemalloc to get the object allocation traceback

The string should not print without await never appears. That is the silent-failure shape the asyncio docs call out: you built an object and threw it away [2].

Catch the shapes that drop work

These patterns all create coroutine objects and then ignore them [2]:

  1. A sync helper that calls work() with no asyncio.run.
  2. A list comprehension that builds coroutines and never awaits ([work() for _ in range(3)]).
  3. A web handler that returns a coroutine by mistake instead of awaiting it.
  4. print(work()), which prints a coroutine repr and never runs the body.

When concurrency is the goal, schedule with create_task (or gather) instead of calling and dropping. Sequential await finishes near the sum of delays; overlapping tasks finish closer to the longest delay. The timed comparison lives in Python create_task vs await [2].

When not to reach for async def

Skip async def when the function only does CPU work with no awaitable I/O. A coroutine function that never awaits still returns a coroutine object, so callers must still await or schedule it, and you gain no overlap [1]. Prefer a plain def for pure sync helpers. If the bottleneck is CPU on classic CPython, see Python GIL threads are not parallel. For overlap versus same-core speedup vocabulary, see Concurrency vs parallelism.

Compare runtimes without mixing claims

Python's model is await-and-schedule. JavaScript queues promise work on a single call stack (JavaScript promises event loop quick start). Go starts work with go and has no await keyword in the same shape (Goroutines vs coroutines, Go without async await).

Trace one suspension point

Await is a suspension point. The coroutine yields control back to the event loop so other ready tasks can run, then resumes when the awaited thing completes [2][3]. That is different from starting a new OS thread. On classic CPython you still share one interpreter lock for bytecode; async helps when you spend time waiting on I/O, not when you burn CPU in a tight loop [1].

sleep_once.py
import asyncio
import time

async def nap(label, seconds):
    print(f"{label} start")
    await asyncio.sleep(seconds)
    print(f"{label} done")
    return label

async def main():
    t0 = time.perf_counter()
    await nap("solo", 0.05)
    print(f"solo wall={time.perf_counter() - t0:.3f}s")

asyncio.run(main())
bash
python3 sleep_once.py

A typical capture looks like:

text
solo start
solo done
solo wall=0.051s

The wall time sits near the sleep delay because nothing else ran in parallel. Replace the single await with two tasks if you want overlap; that comparison belongs on the create_task page [2].

Read the glossary once

The glossary defines a coroutine as an object that can be entered, exited, and resumed at many points, and notes that async def is how you implement them in Python [3]. That definition is why logging repr(coro) is useless as a "did it run?" check: the repr only proves the object exists. Side effects live in the body, and the body starts after await or scheduling [1][3].

Library authors sometimes return awaitables that are not native coroutines (custom objects with __await__). Callers still must await them. The mental model stays the same: building the object is not running the work [2].

Debug with warnings and types

Turn warnings into errors in local scripts when you are hunting dropped work:

warn_as_error.py
import asyncio
import warnings

warnings.filterwarnings("error", category=RuntimeWarning, module="asyncio")

async def orphan():
    return "lost"

async def main():
    orphan()

try:
    asyncio.run(main())
except RuntimeWarning as err:
    print("caught:", err)

When that path raises, you get a hard failure at the point the coroutine dies unused instead of a log line you might miss. In production frameworks, prefer the framework's task factory and exception handlers so orphaned tasks surface in metrics [2].

A second quick check is inspect.iscoroutine(obj) or a plain type(obj).__name__ print. If a handler "returns" a coroutine to a sync WSGI stack, you will see the type name in logs and an empty or wrong HTTP body. Await inside the async view, or schedule explicitly, before the response is finalized [2].

Pair with create_task when overlap matters

Sequential awaits are correct when step two needs step one's result. They are the wrong default when two independent network calls can proceed together. asyncio.create_task schedules a Task so the loop can interleave them [2]. Gather or TaskGroup patterns then wait for the set. Keep cancellation and exception handling in mind: a failed sibling can leave others running unless you cancel or use a structured group [2].

Do not create tasks and then exit the process without awaiting them. Fire-and-forget without a sink is how you reintroduce the never-awaited class of bugs at task scale [2].

Mistakes that keep printing nothing

Calling async def from sync code and treating the return value as the result. You hold a coroutine, not 42.

Swallowing RuntimeWarning in test suites so never-awaited bugs stay silent [2].

Wrapping CPU-only helpers in async def and then wondering why create_task does not speed them up [1].

Using await in a plain def. The language reference rejects that placement [1].

Nesting asyncio.run inside a library helper while an outer loop already exists. Keep asyncio.run at the process entry and await from there [2].

Building a list of coroutines and iterating the list without awaiting each item. The list holds objects; nothing runs until each one is awaited or scheduled [2].

Returning a coroutine from a sync callback that a framework never awaits. The type looks fine in a debugger until you notice the body never printed [2].

What to try next

Print type(result) whenever an "async function did nothing" ticket lands. If the type name is coroutine, decide among await, asyncio.run, or create_task before you dig into network failures. Keep the never-awaited warning turned on in local runs so the garbage collector reports the miss early [2]. For the concurrent scheduling story, open Python create_task vs await. For vocabulary about overlap versus parallel CPU, open Concurrency vs parallelism.

Browse the Dev explainers topic.

Send this to the friend who calls async functions and wonders why nothing prints.

Dark matte cube on a grid floor with one gold arrow entering from the left and three mint-green arrows leaving in different directions, flanked by curved control tracks with gold knobs and a tall translucent glass ring in front.
Calling async def only builds the object; the body stays idle until await or the event loop actually drives it.

Keep this guide

By Full Byte Developer

Filed under Dev explainers

Questions about this guide

Does async def run the body when I call the function?

No. Per the language reference, async def defines a coroutine function. Calling it returns a coroutine object; execution starts when you await or schedule it.

What is a coroutine in the glossary?

Per the Python glossary, coroutines can be entered, exited, and resumed at many points, and can be implemented with async def.

Can I use await outside async def?

Per the language reference, await expressions may only appear in the body of a coroutine function.

How do I run a top-level coroutine?

Per asyncio task docs, use asyncio.run() for the main entry point, or await the coroutine from another coroutine.

What warning means I forgot to await?

CPython emits RuntimeWarning: coroutine was never awaited when a coroutine object is garbage-collected without being awaited or scheduled.

Sources

Next in this stack