File tree Expand file tree Collapse file tree 1 file changed +6
-14
lines changed
Expand file tree Collapse file tree 1 file changed +6
-14
lines changed Original file line number Diff line number Diff line change @@ -244,7 +244,6 @@ static PyObject *
244244psutil_proc_kill (PyObject * self , PyObject * args ) {
245245 HANDLE hProcess ;
246246 long pid ;
247- DWORD exitCode ;
248247
249248 if (! PyArg_ParseTuple (args , "l" , & pid ))
250249 return NULL ;
@@ -266,19 +265,12 @@ psutil_proc_kill(PyObject *self, PyObject *args) {
266265 }
267266
268267 if (! TerminateProcess (hProcess , SIGTERM )) {
269- if (GetLastError () == ERROR_ACCESS_DENIED ) {
270- // ERROR_ACCESS_DENIED (winerror 5) may happen if the
271- // process already died. See:
272- // https://github.com/giampaolo/psutil/issues/1099
273- // https://github.com/giampaolo/psutil/issues/1595
274- if (GetExitCodeProcess (hProcess , & exitCode ) == 0 ) {
275- PyErr_SetFromOSErrnoWithSyscall ("GetExitCodeProcess" );
276- goto error ;
277- }
278- if (exitCode == STILL_ACTIVE ) {
279- PyErr_SetFromOSErrnoWithSyscall ("TerminateProcess" );
280- goto error ;
281- }
268+ // ERROR_ACCESS_DENIED may happen if the process already died. See:
269+ // https://github.com/giampaolo/psutil/issues/1099
270+ // https://github.com/giampaolo/psutil/issues/1595
271+ if ((GetLastError () == ERROR_ACCESS_DENIED ) && \
272+ (psutil_pid_is_running (pid ) == 0 ))
273+ {
282274 CloseHandle (hProcess );
283275 Py_RETURN_NONE ;
284276 }
You can’t perform that action at this time.
0 commit comments