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 328dd0d5f3
commit 1f9a835400
4 changed files with 82 additions and 1 deletions

View file

@ -1075,7 +1075,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