Skip to content

Async Call-Stack Reconstruction #91048

Description

@mpage
mannequin
BPO 46892
Nosy @gvanrossum, @DinoV, @asvetlov, @1st1, @kumaraditya303, @itamaro, @mpage

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:

assignee = None
closed_at = None
created_at = <Date 2022-03-01.22:13:38.844>
labels = ['interpreter-core', '3.11', 'type-feature', 'expert-asyncio']
title = 'Async Call-Stack Reconstruction'
updated_at = <Date 2022-03-12.09:30:23.838>
user = 'https://github.com/mpage'

bugs.python.org fields:

activity = <Date 2022-03-12.09:30:23.838>
actor = 'asvetlov'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Interpreter Core', 'asyncio']
creation = <Date 2022-03-01.22:13:38.844>
creator = 'mpage'
dependencies = []
files = []
hgrepos = []
issue_num = 46892
keywords = []
message_count = 5.0
messages = ['414301', '414884', '414930', '414948', '414985']
nosy_count = 7.0
nosy_names = ['gvanrossum', 'dino.viehland', 'asvetlov', 'yselivanov', 'kumaraditya', 'itamaro', 'mpage']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue46892'
versions = ['Python 3.11']

Linked PRs

Activity

  1. mpage commented on Mar 1, 2022

    mpagemannequin
    MannequinAuthor

    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 42
    

    When 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:

    1. A new limited C-API to set and retrieve the “awaiter” of an awaitable object.
    2. Additions to PyAsyncMethods to store function pointers for setting and retrieving the awaiter on instances.
    3. An API in managed code to retrieve the async call stack as a list of fully qualified names (i.e. <module>:<class>.<function>).
  2. asvetlov commented on Mar 11, 2022

    @asvetlov
    Contributor

    We’d like to merge our implementation into CPython

    Could you provide a link first, please?

  3. mpage commented on Mar 11, 2022

    mpagemannequin
    MannequinAuthor

    Sorry for the confusion, I'm working on a PR. I filed the BPO to gauge interest in the feature.

  4. gvanrossum commented on Mar 11, 2022

    @gvanrossum
    Member

    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.

  5. asvetlov commented on Mar 12, 2022

    @asvetlov
    Contributor

    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.

  6. transferred this issue fromon Apr 10, 2022
  7. 170 remaining items

  8. moved this from Todo to Done in asyncioon Aug 18, 2025
  9. added 2 commits that reference this issue on Aug 19, 2025
  10. added a commit that references this issue on Sep 9, 2025
  11. added 5 commits that reference this issue on Dec 17, 2025
  12. added 4 commits that reference this issue on Jun 2, 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

    Projects

    • Status
      Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions