Python asyncio Recipes/Enable asyncio debug mode

Turn on extra diagnostics while developing.

Section: Debugging and Introspection

Enable asyncio debug mode

python
python
import asyncio

async def main():
    loop = asyncio.get_running_loop()
    loop.set_debug(True)
    await asyncio.sleep(0.1)

asyncio.run(main(), debug=True)
Explanation

Debug mode helps surface slow callbacks, resource warnings, and some misuse patterns.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Debugging and Introspection
Inspect running tasks
List currently active tasks in the running loop.
OpenIn sheetpythonsame section
Bound a worker pool with Semaphore
Throttle async work to a safe level.
Retry an async operation
Retry with simple exponential backoff.
Process input in batches
Break large workloads into fixed-size async chunks.
Cancel cleanly on shutdown
Maintain and cancel outstanding tasks at shutdown time.