-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
subprocess.Popen.send_signal doesn't check whether the process has terminated #51222
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
Comments
When subprocess.Popen.send_signal is called, it simply calls A better behavior would be to raise an exception when self.returncode is |
I agree with Milko. However, I think Popen.send_signal should poll() before sending any In this way, instead of polling before sending signals to check if the I've provided a patch. All the tests pass. However, even though you try the old version of subprocess.py all the |
I totally agree this should be fixed (there was a similar issue for psutil: http://code.google.com/p/psutil/issues/detail?id=58) but communicate() and wait() should be affected in the same manner. Probably it would make sense to add an is_running() method and decorate send_signal(), kill(), communicate() and wait() methods with a function which makes sure that the process is still running, otherwise raises an exception instead. Maybe it would also makes sense to provide a brand new NoSuchProcess exception class. |
It seems to me that raising OSError isn’t quite right. Either the error is more of an internal programmer error, like how writing to a closed file object raises ValueError, or there should not be an error, like when the process has terminated but has not been reaped, or when closing an already-closed file. |
New changeset 6bd3c8623bb2 by Gregory P. Smith in branch '3.4': New changeset bc907c76f054 by Gregory P. Smith in branch '3.5': New changeset e51c46d12ec1 by Gregory P. Smith in branch 'default': |
I chose to go with the "there should not be an error" approach similar to how Python deals with multiple file closes. Both are technically programming errors but the point of Python is make life easier. Reasoning? I don't want someone to ever think they could depend on getting an exception from send_signal/terminate/kill in this "process has already died and someone has called wait or poll to get its return code" situation as that is unreliable and potentially impacts other innocent processes. |
Hello! Sorry for necro but I'm working on PR for xonsh shell and I need your help. In xonsh we have a call where from Thread we call Popen with shell command. And in some cases command can stop working immediately after running (e.g. interactive tool ask input but there is no tty). During tracing I see that How to check that pid is alive? The solution from stackoverflow about |
On POSIX you may use this (note: that may return True if PID is a TID (thread ID)): That won't check whether PID has been reused by another process though, because
|
@giampaolo thanks for the answer! I will try! |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: