Skip to content

python -m asyncio ps shows a single frame for the task that is currently running #158443

Description

@deadlovelll

Bug report

A task that is running is shown with a single frame instead of its call stack.

import asyncio, os, sys

async def coro1():
    return 1

async def c():
    if sys.argv[1] == "spin":
        while True:
            await coro1()
    await asyncio.sleep(100)

async def b(): await c()
async def a(): await b()

async def main():
    print(os.getpid(), flush=True)
    await a()

asyncio.run(main())

Sleep (expected):

./python.exe repro.py sleep
➜  cpython git:(main) ✗ sudo ./python.exe -m asyncio ps 89369
Password:
tid        task id              task name            coroutine stack                                    awaiter chain                                      awaiter name    awaiter id
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
3924274    0x1039d4d70          Task-1               sleep -> c -> b -> a -> main                                                                                          0x0

Spin (actual):

./python.exe repro.py spin
➜  cpython git:(main) ✗ sudo ./python.exe -m asyncio ps 89667
tid        task id              task name            coroutine stack                                    awaiter chain                                      awaiter name    awaiter id
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
3925594    0x105370d70          Task-1               main                                                                                                                  0x0

Proposed fix: For a running task, read the frames from the thread stack, as get_async_stack_trace() already do

I have a fix ready for that

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Linked PRs

Activity

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