Python Glossary Русский

Python 3.14+Async programmingfunction

asyncio.format_call_graph()

call graph

Returns the async call graph of the current task or a given Future as a readable string, for logs and debugging.

Syntax

text = asyncio.format_call_graph(future=None, /, *, depth=1, limit=None)

The string contains object addresses (id=0x...) and full file paths, so tests never compare it whole. Each task is a "* Task(name=...)" line followed by "+ Call stack" and "+ Awaited by". It carries the same data as capture_call_graph, just formatted; print_call_graph prints it directly. Outside a task it returns an empty string. Added in 3.14.

Examples

# Python 3.14+
import asyncio
async def child():
    text = asyncio.format_call_graph()
    print(text.splitlines()[0].startswith("* Task(name='child'"))  # → True
    print('+ Awaited by:' in text)  # → True
async def main():
    await asyncio.create_task(child(), name='child')
asyncio.run(main())

See also

Open in the full glossarydocs.python.orgReport an inaccuracy