changeset: 99147:bc907c76f054 branch: 3.5 parent: 99144:6c733337afae parent: 99146:6bd3c8623bb2 user: Gregory P. Smith date: Sun Nov 15 18:26:11 2015 -0800 files: Lib/subprocess.py Misc/NEWS description: 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. diff -r 6c733337afae -r bc907c76f054 Lib/subprocess.py --- a/Lib/subprocess.py Sat Nov 14 15:14:42 2015 -0800 +++ b/Lib/subprocess.py Sun Nov 15 18:26:11 2015 -0800 @@ -1333,8 +1333,10 @@ 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 @@ 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 @@ 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 diff -r 6c733337afae -r bc907c76f054 Misc/NEWS --- a/Misc/NEWS Sat Nov 14 15:14:42 2015 -0800 +++ b/Misc/NEWS Sun Nov 15 18:26:11 2015 -0800 @@ -70,6 +70,10 @@ Library ------- +- 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. + - Issue #25590: In the Readline completer, only call getattr() once per attribute.