Skip to content

asyncio.print_call_graph() loses the call stack at aiter(callable, stop_value) #157044

Closed as duplicate

Description

@deadlovelll

Bug report

Bug description:

The two-argument form of aiter() hides everything the callable is waiting on. The awaitable it produces exposes nothing about the coroutine it wraps, so the walk stops there

Repro:

import asyncio

async def deep():
    await asyncio.Event().wait()

async def produce():
    await deep()
    return 1

async def worker():
    async for _ in aiter(produce, None):
        pass

async def main():
    t = asyncio.create_task(worker(), name='worker')
    await asyncio.sleep(0.05)
    asyncio.print_call_graph(t)
    t.cancel()

asyncio.run(main())

Expected:

* Task(name='worker', id=0x105e7cb90)
  + Call stack:
  |   File '/Users/timofeiivankov/cpython/Lib/asyncio/locks.py', line 210, in async Event.wait()
  |   File '/Users/timofeiivankov/cpython/repro.py', line 4, in async deep()
  |   File '/Users/timofeiivankov/cpython/repro.py', line 7, in async produce()
  |   File '/Users/timofeiivankov/cpython/repro.py', line 11, in async worker()

Actual:

* Task(name='worker', id=0x105adcb90)
  + Call stack:
  |   File '/Users/timofeiivankov/cpython/repro.py', line 11, in async worker()

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Linked PRs

Activity

  1. deadlovelll commented on Sep 6, 2026

    @deadlovelll
    ContributorAuthor
  2. added 8 commits that reference this issue on Sep 8, 2026
  3. goutamadwant commented on Sep 9, 2026

    @goutamadwant
    Contributor

    @picnixz The callable iterator's frameless awaitable stops the graph traversal. The fix #157202 exposes its wrapped object so traversal reaches the underlying coroutine stack. Pls review and let me know if this fix makes sense. thanks!

  4. kumaraditya303 commented on Sep 12, 2026

    @kumaraditya303
    Contributor
  5. moved this from Todo to Done in asyncioon Sep 19, 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
      Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions