[issue36067] subprocess terminate() "invalid handle" error when process is gone
Giampaolo Rodola'
report at bugs.python.org
Thu Feb 21 11:52:48 EST 2019
Giampaolo Rodola' <g.rodola at gmail.com> added the comment:
I think this is somewhat similar to issue14252. The problem I see is that we should either raise ProcessLookupError or ignore the error (better). This concept of suppressing errors if process is gone is currently already established in 2 places:
https://github.com/python/cpython/blob/bafa8487f77fa076de3a06755399daf81cb75598/Lib/subprocess.py#L1389
Basically what I propose is to extend the existing logic to also include ERROR_INVALID_HANDLE other than ERROR_ACCESS_DENIED. Not tested:
def terminate(self):
"""Terminates the process."""
# Don't terminate a process that we know has already died.
if self.returncode is not None:
return
try:
_winapi.TerminateProcess(self._handle, 1)
except WindowsError as err:
if err.errno in (ERROR_ACCESS_DENIED, ERROR_INVALID_HANDLE):
rc = _winapi.GetExitCodeProcess(self._handle)
if rc == _winapi.STILL_ACTIVE:
raise
self.returncode = rc
else:
raise
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue36067>
_______________________________________
More information about the Python-bugs-list
mailing list