Skip to content

profiling.sampling --async-aware misses main interpreter tasks when subinterpreters exist #158968

Description

@deadlovelll

Bug report

profiling.sampling --async-aware shows tasks from only one interpreter, so the main interpreter's tasks disappear once a subinterpreter exists

Repro:

import asyncio, os, time
from concurrent.futures import InterpreterPoolExecutor

def blocking_work():
    import asyncio, time

    async def sub_spin():
        deadline = time.monotonic() + 60
        while time.monotonic() < deadline:
            pass

    asyncio.run(sub_spin())

async def main():
    loop = asyncio.get_running_loop()
    with InterpreterPoolExecutor() as pool:
        loop.run_in_executor(pool, blocking_work)
        print(os.getpid(), flush=True)
        deadline = time.monotonic() + 60
        while time.monotonic() < deadline:
            pass

asyncio.run(main())

Run:

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

Actual output:

Stack dump for PID 72163, thread 24398118 (task 4404221168; most recent call last):
  File "<task>", in Task-1
  File "repro.py", line 9, in blocking_work.<locals>.sub_spin
    while time.monotonic() < deadline:

Expected:

Stack dump for PID 72163, thread 24398118 (task 4404221168; most recent call last):
  File "<task>", in Task-1
  File "repro.py", line 9, in blocking_work.<locals>.sub_spin
    while time.monotonic() < deadline:

Stack dump, thread 24398104 (task 4379889488; most recent call last):
  File "<task>", in Task-1
  File "repro.py", line 20, in main
    while time.monotonic() < deadline:

Proposed fix: add subinterpreter traversal like #158900 do

I'll work on the fix

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-profilingtopic-subprocessSubprocess issues.type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions