@@ -9582,42 +9582,33 @@ os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal)
9582
9582
9583
9583
Py_RETURN_NONE ;
9584
9584
#else /* !MS_WINDOWS */
9585
- PyObject * result ;
9586
9585
DWORD sig = (DWORD )signal ;
9587
- DWORD err ;
9588
- HANDLE handle ;
9589
9586
9590
9587
#ifdef HAVE_WINDOWS_CONSOLE_IO
9591
9588
/* Console processes which share a common console can be sent CTRL+C or
9592
9589
CTRL+BREAK events, provided they handle said events. */
9593
9590
if (sig == CTRL_C_EVENT || sig == CTRL_BREAK_EVENT ) {
9594
9591
if (GenerateConsoleCtrlEvent (sig , (DWORD )pid ) == 0 ) {
9595
- err = GetLastError ();
9596
- PyErr_SetFromWindowsErr (err );
9597
- }
9598
- else {
9599
- Py_RETURN_NONE ;
9592
+ return PyErr_SetFromWindowsErr (0 );
9600
9593
}
9594
+ Py_RETURN_NONE ;
9601
9595
}
9602
9596
#endif /* HAVE_WINDOWS_CONSOLE_IO */
9603
9597
9604
9598
/* If the signal is outside of what GenerateConsoleCtrlEvent can use,
9605
9599
attempt to open and terminate the process. */
9606
- handle = OpenProcess (PROCESS_ALL_ACCESS , FALSE, (DWORD )pid );
9600
+ HANDLE handle = OpenProcess (PROCESS_ALL_ACCESS , FALSE, (DWORD )pid );
9607
9601
if (handle == NULL ) {
9608
- err = GetLastError ();
9609
- return PyErr_SetFromWindowsErr (err );
9602
+ return PyErr_SetFromWindowsErr (0 );
9610
9603
}
9611
9604
9612
- if (TerminateProcess (handle , sig ) == 0 ) {
9613
- err = GetLastError ();
9614
- result = PyErr_SetFromWindowsErr (err );
9615
- } else {
9616
- result = Py_NewRef (Py_None );
9605
+ BOOL res = TerminateProcess (handle , sig );
9606
+ CloseHandle (handle );
9607
+ if (res == 0 ) {
9608
+ return PyErr_SetFromWindowsErr (0 );
9617
9609
}
9618
9610
9619
- CloseHandle (handle );
9620
- return result ;
9611
+ Py_RETURN_NONE ;
9621
9612
#endif /* !MS_WINDOWS */
9622
9613
}
9623
9614
#endif /* HAVE_KILL */
0 commit comments