summaryrefslogtreecommitdiffstats
path: root/Lib/subprocess.py
diff options
context:
space:
mode:
authorGregory P. Smith <greg@krypto.org>2015-11-16 02:26:11 (GMT)
committerGregory P. Smith <greg@krypto.org>2015-11-16 02:26:11 (GMT)
commit2cd1b3b08912133ff3d33755a9949c2aa0155b95 (patch)
tree8ec5a6388f67724239091a5b318975ef7fb41716 /Lib/subprocess.py
parentfcc2e71e99edb668cad539dc8fa9f259d0b389b6 (diff)
parenta0c9caad66f01328155177180df1c46fe7c62e57 (diff)
downloadcpython-2cd1b3b08912133ff3d33755a9949c2aa0155b95.zip
cpython-2cd1b3b08912133ff3d33755a9949c2aa0155b95.tar.gz
cpython-2cd1b3b08912133ff3d33755a9949c2aa0155b95.tar.bz2
Fix issue #6973: When we know a subprocess.Popen process has died, do
not allow the send_signal(), terminate(), or kill() methods to do anything as they could potentially signal a different process.
Diffstat (limited to 'Lib/subprocess.py')
-rw-r--r--Lib/subprocess.py19
1 files changed, 12 insertions, 7 deletions
diff --git a/Lib/subprocess.py b/Lib/subprocess.py
index b6c4374..bbf50ce 100644
--- a/Lib/subprocess.py
+++ b/Lib/subprocess.py
@@ -1333,8 +1333,10 @@ class Popen(object):
return (stdout, stderr)
def send_signal(self, sig):
- """Send a signal to the process
- """
+ """Send a signal to the process."""
+ # Don't signal a process that we know has already died.
+ if self.returncode is not None:
+ return
if sig == signal.SIGTERM:
self.terminate()
elif sig == signal.CTRL_C_EVENT:
@@ -1345,8 +1347,10 @@ class Popen(object):
raise ValueError("Unsupported signal: {}".format(sig))
def terminate(self):
- """Terminates the process
- """
+ """Terminates the process."""
+ # Don't terminate a process that we know has already died.
+ if self.returncode is not None:
+ return
try:
_winapi.TerminateProcess(self._handle, 1)
except PermissionError:
@@ -1754,9 +1758,10 @@ class Popen(object):
def send_signal(self, sig):
- """Send a signal to the process
- """
- os.kill(self.pid, sig)
+ """Send a signal to the process."""
+ # Skip signalling a process that we know has already died.
+ if self.returncode is None:
+ os.kill(self.pid, sig)
def terminate(self):
"""Terminate the process with SIGTERM