Python Glossary Русский

Python 3.14+Async programmingfunction

asyncio.print_call_graph()

call graph

Prints the async call graph of the current task or a given Future: the coroutine's stack and the chain of tasks awaiting it.

Syntax

asyncio.print_call_graph(future=None, /, *, file=None, depth=1, limit=None)

The asyncio counterpart of traceback.print_stack(): a plain stack ends at the task boundary, while this shows who awaits whom. It writes to sys.stdout by default, not stderr as traceback does; the file argument redirects it, for example into io.StringIO or a log file. The output contains paths and addresses, so it differs between runs. Added in 3.14.

Examples

# Python 3.14+
import asyncio
import io
async def child():
    buf = io.StringIO()
    asyncio.print_call_graph(file=buf, limit=0)
    print(buf.getvalue().count('* Task('))  # → 2 — child и ждущая её main
async def main():
    await asyncio.create_task(child(), name='child')
asyncio.run(main())

See also

Open in the full glossarydocs.python.orgReport an inaccuracy