1 """Script used to test os.kill on Windows, for issue #1220212
3 This script is started as a subprocess in test_os and is used to test the
4 CTRL_C_EVENT and CTRL_BREAK_EVENT signals, which requires a custom handler
5 to be written into the kill target.
7 See http://msdn.microsoft.com/en-us/library/ms685049%28v=VS.85%29.aspx for a
11 from ctypes
import wintypes
15 # Function prototype for the handler function. Returns BOOL, takes a DWORD.
16 HandlerRoutine
= wintypes
.WINFUNCTYPE(wintypes
.BOOL
, wintypes
.DWORD
)
18 def _ctrl_handler(sig
):
19 """Handle a sig event and return 0 to terminate the process"""
20 if sig
== signal
.CTRL_C_EVENT
:
22 elif sig
== signal
.CTRL_BREAK_EVENT
:
25 print("UNKNOWN EVENT")
28 ctrl_handler
= HandlerRoutine(_ctrl_handler
)
31 SetConsoleCtrlHandler
= ctypes
.windll
.kernel32
.SetConsoleCtrlHandler
32 SetConsoleCtrlHandler
.argtypes
= (HandlerRoutine
, wintypes
.BOOL
)
33 SetConsoleCtrlHandler
.restype
= wintypes
.BOOL
35 if __name__
== "__main__":
36 # Add our console control handling function with value 1
37 if not SetConsoleCtrlHandler(ctrl_handler
, 1):
38 print("Unable to add SetConsoleCtrlHandler")
41 # Do nothing but wait for the signal