Skip to content

Remote asyncio stack traces stop at async generators #159620

Open

Description

@deadlovelll

Bug report

Stacks of tasks suspended in async for, anext() or aclose() end before the async generator, so its frames and everything it awaits are missing

Repro:

import asyncio
import os

async def agen():
    await asyncio.sleep(3600)
    yield

async def main():
    async for _ in agen():
        pass

print(os.getpid())
asyncio.run(main())

Run (for example i took asyncio pstree)

sudo ./python.exe -m asyncio pstree <pid>

Actual:

└── (T) Task-1
    └──  main /Users/timofeiivankov/cpython/repro.py:9

Expected:

└── (T) Task-1
    └──  main /Users/timofeiivankov/cpython/repro.py:9
        └──  agen /Users/timofeiivankov/cpython/repro.py:5
            └──  sleep /Users/timofeiivankov/cpython/Lib/asyncio/tasks.py:723

It also affecting those commands:

sudo ./python.exe -m asyncio ps <pid>
sudo ./python.exe -m profiling.sampling dump --async-aware <pid>
sudo ./python.exe -m profiling.sampling run -d 5 --async-aware --async-mode all repro.py
sudo ./python.exe -m profiling.sampling attach -d 5 --async-aware --async-mode all <pid>

But to avoid blowing the issue out of proportion, I decided to just mention them

Proposed fix: follow asend/athrow wrappers to their async generator when walking the coroutine chain

I have a fix ready

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Linked PRs

Activity

  1. added
    stdlibStandard Library Python modules in the Lib/ directory
    on Oct 17, 2026
  2. added 5 commits that reference this issue on Oct 17, 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