-
Notifications
You must be signed in to change notification settings - Fork 142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Debugger hangs and process left unterminated when forking inside subprocess.run #264
Comments
I'll start to investigate this. |
I wasn't able to investigate this properly last time, so, I'll start tackling this again. |
Attaching related logs. Changed the program to give a bit more info:
debugger.vscode_79413804-5bb5-48f7-b650-fb10716ff2a1.log <- initial launch (receives debugpyAttach to 19300) debugpy.adapter-19269.log <-- it's possible to see that it receives the connection from pydevd in debugpy.launcher-19279.log debugpy.pydevd.19285.log initial process
debugpy.pydevd.19311.log shows connection done, but initialize is not received. The logs on the pydevd side seem to show that a connection was done, but the initialize event isn't really sent after that (I also tested in plain pydevd and it seems to work properly there, so, it's probably something related to the connection management on the debugpy/vscode side). |
Actually, the problem was on the pydevd side. It wasn't properly keeping the protocol after a fork after a subprocess. This happened because debugpy set the default protocol in memory, but that in-memory default was lost if it first created a subprocess and then a fork after that subprocess and the logging doesn't really show which protocol it was using (the message just didn't arrive in the other side because there was no new-line sent) -- took me a while to actually find this one (and as all hard to debug things it's a really small fix: https://github.com/microsoft/debugpy/pull/438/files#diff-942a2e05c676f6fb0f7a70883d2f885bcb47c1af4feb1a3a48f57fd77c17d5b5R685). |
Environment data
Expected behaviour
Spawned process terminate successfully (exit with 0) and debugging continues finally terminating the parent process
Actual behaviour
When capturing stdout (
stdout=subprocess.PIPE
) the parent process hangs indefintely waiting for the child process. When not capturing stdout the forked child process hangs and is never terminated.Steps to reproduce:
This happened in a complex scenario which went like this: Python script starts another python script, which invokes an external tool (compiler via
distutils
)I reduces this to the following code by checking what is happening:
stdout=subprocess.PIPE
line and observe that the subprocesses-child-pid (return value of fork) is printed but the child never runs (which should print a zero) and although debugging will end in this case the child process is never terminated (checkps -aux | grep python
)Note that usually the parent process of the
fork
waits for the child which means that again the debugged process never returns/continues.The text was updated successfully, but these errors were encountered: