This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author giampaolo.rodola
Recipients giampaolo.rodola, vstinner
Date 2019-02-21.16:52:48
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1550767968.68.0.591840501491.issue36067@roundup.psfhosted.org>
In-reply-to
Content
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
History
Date User Action Args
2019-02-21 16:52:48giampaolo.rodolasetrecipients: + giampaolo.rodola, vstinner
2019-02-21 16:52:48giampaolo.rodolasetmessageid: <1550767968.68.0.591840501491.issue36067@roundup.psfhosted.org>
2019-02-21 16:52:48giampaolo.rodolalinkissue36067 messages
2019-02-21 16:52:48giampaolo.rodolacreate