Issue #14252: Fix subprocess.Popen.terminate() to not raise an error under Windows when the child process has already exited.

This commit is contained in:
Antoine Pitrou 2012-03-11 19:29:12 +01:00
parent 5081957642
commit f60845b70a
4 changed files with 82 additions and 1 deletions

View file

@ -1016,7 +1016,17 @@ class Popen(object):
def terminate(self):
"""Terminates the process
"""
_subprocess.TerminateProcess(self._handle, 1)
try:
_subprocess.TerminateProcess(self._handle, 1)
except OSError as e:
# ERROR_ACCESS_DENIED (winerror 5) is received when the
# process already died.
if e.winerror != 5:
raise
rc = _subprocess.GetExitCodeProcess(self._handle)
if rc == _subprocess.STILL_ACTIVE:
raise
self.returncode = rc
kill = terminate