diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2012-03-11 18:29:12 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2012-03-11 18:29:12 (GMT) |
commit | 1f9a8354002dbb29f38bfbd4273ce62e40ac80ba (patch) | |
tree | eaaaf85cefe62ad490202984e2a0dd2a425eabe7 /Lib/subprocess.py | |
parent | 328dd0d5f3d20c01d85675f6e5d1001dd2a04480 (diff) | |
download | cpython-1f9a8354002dbb29f38bfbd4273ce62e40ac80ba.zip cpython-1f9a8354002dbb29f38bfbd4273ce62e40ac80ba.tar.gz cpython-1f9a8354002dbb29f38bfbd4273ce62e40ac80ba.tar.bz2 |
Issue #14252: Fix subprocess.Popen.terminate() to not raise an error under Windows when the child process has already exited.
Diffstat (limited to 'Lib/subprocess.py')
-rw-r--r-- | Lib/subprocess.py | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/Lib/subprocess.py b/Lib/subprocess.py index 017f58d..179f41a 100644 --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -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 |