GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — `python -m profiling.sampling --async-aware` shows one frame for a task whose coroutine recurses · Issue #158522 · python/cpython

python -m profiling.sampling --async-aware shows one frame for a task whose coroutine recurses #158522

New issue
Copy link
New issue
Copy link
Closed
Closed
python -m profiling.sampling --async-aware shows one frame for a task whose coroutine recurses#158522
Copy link
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-profilingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@deadlovelll
deadlovelll
opened on Sep 30, 2026
Issue body actions

Bug report

A task whose coroutine recurses is shown with only one frame in the profiler dump

Repro:

import asyncio, os, time

async def rec(n):
    if n:
        await rec(n - 1)
    else:
        print(os.getpid(), flush=True)
        t0 = time.monotonic()
        while time.monotonic() - t0 < 30:
            pass

async def main():
    await asyncio.create_task(rec(4))

asyncio.run(main())

Run:

./python.exe repro.py
sudo ./python.exe -m profiling.sampling dump --async-aware --async-mode running <pid>

Actual:

Stack dump for PID 68355, thread 4566646 (task 4392209776; most recent call last):
  File "<task>", in Task-1
  File "repro.py", line 13, in main
    await asyncio.create_task(rec(4))
  File "<task>", in Task-2
  File "repro.py", line 9, in rec
    while time.monotonic() - t0 < 30:

Expected:

Stack dump for PID 67670, thread 4562857 (task 4376759664; most recent call last):
  File "<task>", in Task-1
  File "repro.py", line 13, in main
    await asyncio.create_task(rec(4))
  File "<task>", in Task-2
  File "repro.py", line 5, in rec
    await rec(n - 1)
  File "repro.py", line 5, in rec
    await rec(n - 1)
  File "repro.py", line 5, in rec
    await rec(n - 1)
  File "repro.py", line 5, in rec
    await rec(n - 1)
  File "repro.py", line 9, in rec
    while time.monotonic() - t0 < 30:

Proposed fix: Stop the frame walk at the task's own frame instead of its code object

I have a fix ready

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Linked PRs

  • gh-158522: Fix truncated stack for a task whose coroutine recurses #158526
  • [3.15] gh-158522: Fix truncated stack for a task whose coroutine recurses (GH-158526) #158870

Activity

  1. deadlovelll
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Sep 30, 2026
  2. deadlovelll
    changed the title [-]`python -m profiling.sampling --async-aware` shows one frame for a task whose coroutine recurses.[/-] [+]`python -m profiling.sampling --async-aware` shows one frame for a task whose coroutine recurses[/+] on Sep 30, 2026
  3. picnixz
    added
    topic-profiling
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    and removed
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    topic-profiling
    on Oct 1, 2026
  4. pablogsal
    added 3 commits that reference this issue on Oct 5, 2026

    gh-158522: Fix truncated stack for a task whose coroutine recurses (#…

    05302c0

    [3.15] gh-158522: Fix truncated stack for a task whose coroutine recu…

    a904b39

    Revert "[3.15] pythongh-158522: Fix truncated stack for a task whose …

    b3cfee3
  5. hugovk
    closed this as completedon Oct 11, 2026
  6. pablogsal
    added a commit that references this issue on Oct 11, 2026

    [3.15] Restore deferred backports for 3.15.1, including GH-158874 (#1…

    4ceb3fa
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/ directoryStandard Library Python modules in the Lib/ directorytopic-profilingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.