summaryrefslogtreecommitdiffstats
path: root/Lib/subprocess.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2012-03-11 18:29:12 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2012-03-11 18:29:12 (GMT)
commit1f9a8354002dbb29f38bfbd4273ce62e40ac80ba (patch)
treeeaaaf85cefe62ad490202984e2a0dd2a425eabe7 /Lib/subprocess.py
parent328dd0d5f3d20c01d85675f6e5d1001dd2a04480 (diff)
downloadcpython-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.py12
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