microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
163.29k stars 28.9k forks source link

"Stop Debugging" variant for terminating entire process tree #230850

Open Birch-san opened 22 hours ago

Birch-san commented 22 hours ago
image

I'd really like for "Stop Debugging" (or a variant thereof) to terminate the entire process tree.

Debugging multi-process applications is common in Python / pytorch, but to "Stop" my application I need to press Stop per subprocess.

I have to press stop over 10 times to kill a realistic program — because each time I press Stop, it then takes me to the next subprocess, and we have subprocesses for dataloader workers, per-GPU model workers, model compilation workers… and it moves my focus every time. I get further and further from the line of code or problem that made me want to Stop the program, and by the end of the carousel my focus is left inside the torchrun wrapper script, which is never where I'm doing development.

the consequence right now is that I avoid as far as possible running my application in a realistic way. I reduce processes until it's down to just 3, so that I only have to press stop 3 times to terminate the program.

pressing "Restart" basically doesn't work, because a new process cannot be started until all processes from the current run have been killed. so for my most common task "run until I hit a problem, hit restart": I have to hit Stop 3 times then Run, when what I really want is to just hit restart once.

possible solutions:

I think I'd want gentle termination of the subprocesses, but to disconnect the debugger so I don't have to watch the shutdown procedure and all the exceptions that get raised along the way.

thanks for any consideration you can give this!

Birch-san commented 22 hours ago

one challenge could be "how do you kill a process tree" / "is it sufficient to just kill the parent".

on POSIX systems (macOS, Linux, etc) I think this is just:

on Win32 systems emulating POSIX semantics via Cygwin/MSYS2, killing process trees gently (i.e. emulating POSIX's SIGTERM semantics) is a bit different… I took some notes on this a while ago:

and found these to be useful references regarding "how do you emulate SIGTERM on Windows":

https://stackoverflow.com/questions/48199794/winpty-and-git-bash
https://github.com/mintty/mintty/issues/56
https://github.com/mintty/mintty/issues/376
https://github.com/msys2/MINGW-packages/issues/2645#issuecomment-312242133
https://github.com/mintty/mintty/wiki/Tips#inputoutput-interaction-with-alien-programs
https://stackoverflow.com/questions/44788982/node-js-ctrl-c-doesnt-stop-server-after-starting-server-with-npm-start/51078011#51078011
https://github.com/nodejs/node/issues/16103
https://github.com/git-for-windows/MSYS2-packages/commit/f4fda0f30aa04eb296128f11841dd4198e4e90ed

but maybe I'm overthinking this, or maybe a simple solution can be developed for POSIX systems before confronting "what to do on Windows". you also have access to the terminal, which probably emulates these semantics already; could initiate a termination from the terminal then detach the debugger from all processes.