summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2019-11-20 02:09:02 -0800
committerGiampaolo Rodola <g.rodola@gmail.com>2019-11-20 02:09:02 -0800
commitf7e898b0987f97352c7551bdd9b29b594e1236f6 (patch)
treec4e80c8f11aab6e7e4b2a80278530869e2d5b0c7
parent72c84cb4edb5c0968a83c1f45ad5cc51235e0af3 (diff)
downloadpsutil-f7e898b0987f97352c7551bdd9b29b594e1236f6.tar.gz
#1595: use psutil_pid_is_running() instead of GetExitCodeProcess
-rw-r--r--psutil/_psutil_windows.c20
1 files changed, 6 insertions, 14 deletions
diff --git a/psutil/_psutil_windows.c b/psutil/_psutil_windows.c
index e01fa50d..be0b2337 100644
--- a/psutil/_psutil_windows.c
+++ b/psutil/_psutil_windows.c
@@ -244,7 +244,6 @@ static PyObject *
psutil_proc_kill(PyObject *self, PyObject *args) {
HANDLE hProcess;
long pid;
- DWORD exitCode;
if (! PyArg_ParseTuple(args, "l", &pid))
return NULL;
@@ -266,19 +265,12 @@ psutil_proc_kill(PyObject *self, PyObject *args) {
}
if (! TerminateProcess(hProcess, SIGTERM)) {
- if (GetLastError() == ERROR_ACCESS_DENIED) {
- // ERROR_ACCESS_DENIED (winerror 5) may happen if the
- // process already died. See:
- // https://github.com/giampaolo/psutil/issues/1099
- // https://github.com/giampaolo/psutil/issues/1595
- if (GetExitCodeProcess(hProcess, &exitCode) == 0) {
- PyErr_SetFromOSErrnoWithSyscall("GetExitCodeProcess");
- goto error;
- }
- if (exitCode == STILL_ACTIVE) {
- PyErr_SetFromOSErrnoWithSyscall("TerminateProcess");
- goto error;
- }
+ // ERROR_ACCESS_DENIED may happen if the process already died. See:
+ // https://github.com/giampaolo/psutil/issues/1099
+ // https://github.com/giampaolo/psutil/issues/1595
+ if ((GetLastError() == ERROR_ACCESS_DENIED) && \
+ (psutil_pid_is_running(pid) == 0))
+ {
CloseHandle(hProcess);
Py_RETURN_NONE;
}