benfred / py-spy

Sampling profiler for Python programs
MIT License
12.14k stars 400 forks source link

Subprocess and json flags don't work together #601

Open JRoper18 opened 11 months ago

JRoper18 commented 11 months ago

Specifying both the json and subprocess flags will only print out the dump of the root process and will ignore subprocesses. For example, when running the following python program:

import time
from multiprocessing import Process
def work():
    time.sleep(1000)

for _ in range(10):
    p = Process(target=work, daemon=True)
    p.start()

time.sleep(1000)

And then running:

py-spy dump -js --pid <pid>

Will only return the dump of the root process:

[
  {
    "pid": 16866,
    "thread_id": 140634802636608,
    "thread_name": "MainThread",
    "os_thread_id": 16866,
    "active": false,
    "owns_gil": false,
    "frames": [
      {
        "name": "<module>",
        "filename": "main.py",
        "module": null,
        "short_filename": "main.py",
        "line": 10,
        "locals": null
      }
    ],
    "process_info": null
  }
]

I would expect it to return dumps of all the processes/threads, instead.