`asyncio.print_call_graph()` loses the call stack at anext(agen, default) · Issue #157032 · python/cpython · GitHub
Skip to content

asyncio.print_call_graph() loses the call stack at anext(agen, default) #157032

Description

@deadlovelll

Bug report

Bug description:

Adding a default to anext() hides everything the generator is waiting on

Repro:

import asyncio

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

async def rows():
    await deep()
    yield 1

async def worker():
    await anext(rows(), None)

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=0x103a049b0)
  + 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 generator rows()
  |   File '/Users/timofeiivankov/cpython/repro.py', line 11, in async worker()

Actual:

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

Proposed fix: expose ag_gen on anext_awaitable like #156984 do

Important: Currently this issue have a blocker from #156984 (issue - #156980) because it depends on the fix of it. I have a fix ready and will open a PR once #156984 is merged

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Activity

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