mirror of
https://github.com/python/cpython.git
synced 2025-08-12 12:58:50 +00:00
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:
parent
5081957642
commit
f60845b70a
4 changed files with 82 additions and 1 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue