-
-
Notifications
You must be signed in to change notification settings - Fork 40
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
Console breaks subprocesses stdout/stderr PIPE if script finishes before the subprocess #118
Comments
Does this happen if you run your code in qtconsole instead of Spyder? |
Ok, thanks for checking that out. We'll take a look at this as soon as we can. |
I noticed something interesting that may or may not help. The documentation for subprocess says:
In my above code, is use Popen with To test:
subprocess dies when I hit CTRL-C.
subprocess lives through KeyboardInterrupt and finishes. I get the same result giving |
I think I've nailed down the problem.
A few scenarios:
Turns out spyder wasn't killing my subprocesses, but was instead breaking the PIPE when the script exited. The shell script would then keep running until it reached it's next echo statement, then would find the broken pipe and exit with a SIGPIPE return code. The issue I had before is that I had no way of retrieving that return code, since the python script had already exited, so I just assumed it was killing the processes. The touch lines I was putting in to measure progress were after the echo lines, and so never got run. I assume the bug here is something to do with how spyder is grabbing the stdout and/or subprocess.PIPE in order to print to the console. |
A little unrelated, but while I've been playing with this, I also noticed that whatever spyder does to pipe stdout/stderr and print to the console isn't thread safe. |
Thanks for your thorough investigation of this problem. I think I know what's causing this now and I'll make a pull request to fix it soon. |
I have some code that launches a bunch of subprocesses and waits for return values. I'm trying to implement it in a way that the subprocesses will continue running and finish when I catch a KeyboardInterrupt.
I have code that achieves this, but I've noticed that the spyder console will kill the subprocesses if the launching python script exits before they finish. This only occurs in the spyder console and not in python or ipython run from the terminal. See below.
Original Code:
the relevant bash script
test_sigint.sh
looks like:If I run this code and then hit CTRL-C while the subprocesses are sleeping, it waits for them to finish and gathers the return codes, then prints them and exits. This is what I expect.
I now edit the code so that it isn't waiting on the processes in the except block anymore
What I expect to happen is that the python will print an empty list because the subprocesses haven't returned yet, but they will continue running in the background anyway. What happens, in the spyder console, is that as soon as the python script exits, the subprocesses are killed.
If I run exactly the same script in an ipython instance from the terminal, the script finishes how I expect, i.e. the subprocesses keep running and eventually exit.
So it seems something about spyder (or spyder-kernels i assume) is causing it to kill the subprocesses when it shouldn't.
I had wondered if maybe it was just preventing the subprocesses from printing to screen, so I played around with putting a touch statement at the end of the bash script and found that when run from spyder, those files never got touched.
Relevant details from conda list:
The text was updated successfully, but these errors were encountered: