mirror of
https://github.com/python/cpython.git
synced 2025-08-27 04:05:34 +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:
commit
b69ef16fe6
4 changed files with 80 additions and 1 deletions
|
@ -1162,7 +1162,15 @@ class Popen(object):
|
|||
def terminate(self):
|
||||
"""Terminates the process
|
||||
"""
|
||||
_subprocess.TerminateProcess(self._handle, 1)
|
||||
try:
|
||||
_subprocess.TerminateProcess(self._handle, 1)
|
||||
except PermissionError:
|
||||
# ERROR_ACCESS_DENIED (winerror 5) is received when the
|
||||
# process already died.
|
||||
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