Eryk Sun added the comment:
> I don't understand why any patch for CPython is needed at all.
If and operation on self._handle fails as an invalid handle (due to an
underlying STATUS_INVALID_HANDLE or STATUS_OBJECT_TYPE_MISMATCH), then call
self._handle.Detach() and re-raise the exception.
Alexey Izbyshev added the comment:
> Interesting. Because both errors/conditions are mapped to
> ERROR_INVALID_HANDLE we need the creation time. I can work on a patch for
> that.
I don't understand why any patch for CPython is needed at all. Using invalid
handles is a serious programming
Giampaolo Rodola' added the comment:
Interesting. Because both errors/conditions are mapped to ERROR_INVALID_HANDLE
we need the creation time. I can work on a patch for that. Potentially I can
also include OSX, Linux and BSD* implementations for methods involving
os.kill(pid). That would be
Eryk Sun added the comment:
The subprocess Handle object is never finalized explicitly, so the Process
handle should always be valid as long as we have a reference to the Popen
instance. We can call TerminateProcess as many times as we want, and the handle
will still be valid. If it's
Giampaolo Rodola' added the comment:
On POSIX there is that risk, yes. As for Windows, the termination is based on
the process handle instead of the PID, but I am not sure if that makes a
difference. The risk of reusing the PID/handle is not related to this issue
though. The solution I
STINNER Victor added the comment:
> _winapi.TerminateProcess(self._handle, 1)
> OSError: [WinError 6] The handle is invalid
Silently ignoring that would be dangerous.
There is a risk that the handle is reused by another process and so that you
terminate an unrelated process, no?
--
STINNER Victor added the comment:
I'm not sure of the purpose of this issue.
It's expected to get an error if you try to send a signal to process which is
already terminated.
vstinner@apu$ python3
Python 3.7.2 (default, Jan 16 2019, 19:49:22)
>>> import subprocess
>>>
Giampaolo Rodola' 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:
New submission from Giampaolo Rodola' :
Happened in psutil:
https://ci.appveyor.com/project/giampaolo/psutil/builds/22546914/job/rlp112gffyf2o30i
==
ERROR: psutil.tests.test_process.TestProcess.test_halfway_terminated_process