Repository navigation
Async Call-Stack Reconstruction #91048
Description
Activity
Profiling tools that use the call-stack (i.e. all of them) paint an incomplete picture of what’s really going on in async-heavy codebases. They can only show the stack of the currently executing task; they miss the chain of awaitables that are transitively waiting on the current task. To remedy this, we have added support in Cinder to expose the async call-stack. This consists of the call stack for the currently executing task, followed by the chain of awaitables that are transitively reachable from the currently executing task. See below for a clarifying example.
async def f1(): return await f2() async def f2(): return await asyncio.ensure_future(f3()) async def f3(): return await f4() async def f4(): await asyncio.sleep(10) return 42When retrieved from f4, the two different stacks (top-of-stack last) are:
sync - [f3, f4]
async - [f1, f2, f3, f4]We’d like to merge our implementation into CPython so that other heavy users of asyncio can benefit. This will consist of a few parts:
- A new limited C-API to set and retrieve the “awaiter” of an awaitable object.
- Additions to PyAsyncMethods to store function pointers for setting and retrieving the awaiter on instances.
- An API in managed code to retrieve the async call stack as a list of fully qualified names (i.e. <module>:<class>.<function>).
Reacted by Bruno Cabral, Itamar Oren, Zsolt Dollenstein, Jon Janzen, gfolkmanis-nhgh, Zeke Marffy, Savio Mak, Isaac Nygaard and Daniel Limón- added3.11only security fixesonly security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancementA feature request or enhancement
on Mar 1, 2022 We’d like to merge our implementation into CPython
Could you provide a link first, please?
Sorry for the confusion, I'm working on a PR. I filed the BPO to gauge interest in the feature.
I've recently dabbled a bit in some new primitives for asyncio, and based on that experience I think this would be very useful.
IIRC Trio does this (presumably at considerable cost) in userland.
The idea looks interesting.
The devil in the details I guess.
I'm curious what is the memory and performance penalty.
Waiting for the PR as the discussion starting point.170 remaining items
Load more actions- added 5 commits that reference this issue
on Dec 17, 2025 - added 4 commits that reference this issue
on Jun 2, 2026
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsDone
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
Linked PRs
asyncio-graph.rstdoc #129224_asyncio.future_discard_from_awaited_by#129731_remotedebugging& rename to_remote_debugging#133398asyncio pstree#133478