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 asyncio pstree` loses nodes on Task → Future → Task chains · Issue #161502 · python/cpython

python -m asyncio pstree loses nodes on Task → Future → Task chains #161502

New issue
Copy link
New issue
Copy link
Open
Open
python -m asyncio pstree loses nodes on Task → Future → Task chains#161502
Copy link
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-asynciotype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@deadlovelll
deadlovelll
opened on Nov 6, 2026
Issue body actions

Bug report

When one task awaits another through a Future, python -m asyncio pstree omits the awaited task from the tree

Repro:

import asyncio
import os

async def main():
    asyncio.current_task().set_name("main")
    task = asyncio.create_task(asyncio.sleep(3600), name="worker")
    future = asyncio.get_running_loop().create_future()
    asyncio.future_add_to_awaited_by(task, future)
    task.add_done_callback(future.set_result)
    print(os.getpid(), flush=True)
    try:
        await future
    finally:
        asyncio.future_discard_from_awaited_by(task, future)


asyncio.run(main())

Run:

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

Output:

└── (T) main
    └──  main /Users/timofeiivankov/cpython/repro.py:12

Expected output:

└── (T) main
    └──  main /Users/timofeiivankov/cpython/repro.py:12
        └── (F) Future-0x104e82a80
            └── (T) worker
                └──  sleep /Users/timofeiivankov/cpython/Lib/asyncio/tasks.py:733

For example asyncio.print_call_graph() works with this well:

import asyncio

async def worker():
    asyncio.print_call_graph(limit=0)
    
async def main():
    asyncio.current_task().set_name("main")
    task = asyncio.create_task(worker(), name="worker")
    future = asyncio.get_running_loop().create_future()
    asyncio.future_add_to_awaited_by(task, future)
    task.add_done_callback(future.set_result)
    try:
        await future
    finally:
        asyncio.future_discard_from_awaited_by(task, future)

asyncio.run(main())
* Task(name='worker', id=0x1014d47d0)
  + Awaited by:
    * Future(id=0x10115ea80)
      + Awaited by:
        * Task(name='main', id=0x1014d45f0)

Proposed fix: add Future support in the _remote_debugging

I'll work on this

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Linked PRs

  • gh-161502: Fix missing tasks in asyncio pstree with intermediate Futures #161508

Activity

  1. deadlovelll
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Nov 6, 2026
  2. deadlovelll
    changed the title [-]`python -m asyncio pstree` losing nodes on Task → Future → Task chains[/-] [+]`python -m asyncio pstree` loses nodes on Task → Future → Task chains[/+] on Nov 6, 2026
  3. deadlovelll
    added a commit that references this issue on Nov 6, 2026

    pythongh-161502: Fix missing tasks in asyncio pstree with intermediat…

    19a2241
  4. NekoAsakura
    added
    topic-asyncio
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    on Nov 6, 2026
  5. github-project-automation
    added this to asyncioon Nov 6, 2026
  6. github-project-automation
    moved this to Todo in asyncioon Nov 6, 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/ directoryStandard Library Python modules in the Lib/ directorytopic-asynciotype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    • asyncio
      Status
      Todo
      Show more project fields

    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.