Skip to content

asyncio.print_call_graph() includes event loop frames when depth exceeds the task stack #161124

Open

Description

@deadlovelll

Bug report

Excessive depth makes asyncio.print_call_graph() include event loop internals

Repro:

import asyncio

async def main():
    asyncio.print_call_graph(depth=2)

asyncio.run(main())

Actual:

* Task(name='Task-1', id=0x101ff85f0)
  + Call stack:
  |   File '/Users/timofeiivankov/cpython/Lib/asyncio/events.py', line 91, in Handle._run()
  |   File '/Users/timofeiivankov/cpython/Lib/asyncio/base_events.py', line 2092, in BaseEventLoop._run_once()
  |   File '/Users/timofeiivankov/cpython/Lib/asyncio/base_events.py', line 683, in BaseEventLoop.run_forever()
  |   File '/Users/timofeiivankov/cpython/Lib/asyncio/base_events.py', line 712, in BaseEventLoop.run_until_complete()
  |   File '/Users/timofeiivankov/cpython/Lib/asyncio/runners.py', line 130, in Runner.run()
  |   File '/Users/timofeiivankov/cpython/Lib/asyncio/runners.py', line 211, in run()
  |   File '/Users/timofeiivankov/cpython/repro.py', line 6, in <module>()

Expected:

* Task(name='Task-1', id=0x1011345f0)

Proposed fix: apply depth after collecting the stack up to the task boundary

I'll work on the fix

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Linked PRs

Activity

  1. added a commit that references this issue on Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytopic-asynciotype-bugAn unexpected behavior, bug, or error

    Projects

    • Status
      Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions