]> git.proxmox.com Git - mirror_edk2.git/blame - AppPkg/Applications/Python/Python-2.7.2/Lib/test/win_console_handler.py
EmbeddedPkg: Extend NvVarStoreFormattedLib LIBRARY_CLASS
[mirror_edk2.git] / AppPkg / Applications / Python / Python-2.7.2 / Lib / test / win_console_handler.py
CommitLineData
4710c53d 1"""Script used to test os.kill on Windows, for issue #1220212\r
2\r
3This script is started as a subprocess in test_os and is used to test the\r
4CTRL_C_EVENT and CTRL_BREAK_EVENT signals, which requires a custom handler\r
5to be written into the kill target.\r
6\r
7See http://msdn.microsoft.com/en-us/library/ms685049%28v=VS.85%29.aspx for a\r
8similar example in C.\r
9"""\r
10\r
11from ctypes import wintypes, WINFUNCTYPE\r
12import signal\r
13import ctypes\r
14import mmap\r
15import sys\r
16\r
17# Function prototype for the handler function. Returns BOOL, takes a DWORD.\r
18HandlerRoutine = WINFUNCTYPE(wintypes.BOOL, wintypes.DWORD)\r
19\r
20def _ctrl_handler(sig):\r
21 """Handle a sig event and return 0 to terminate the process"""\r
22 if sig == signal.CTRL_C_EVENT:\r
23 pass\r
24 elif sig == signal.CTRL_BREAK_EVENT:\r
25 pass\r
26 else:\r
27 print("UNKNOWN EVENT")\r
28 return 0\r
29\r
30ctrl_handler = HandlerRoutine(_ctrl_handler)\r
31\r
32\r
33SetConsoleCtrlHandler = ctypes.windll.kernel32.SetConsoleCtrlHandler\r
34SetConsoleCtrlHandler.argtypes = (HandlerRoutine, wintypes.BOOL)\r
35SetConsoleCtrlHandler.restype = wintypes.BOOL\r
36\r
37if __name__ == "__main__":\r
38 # Add our console control handling function with value 1\r
39 if not SetConsoleCtrlHandler(ctrl_handler, 1):\r
40 print("Unable to add SetConsoleCtrlHandler")\r
41 exit(-1)\r
42\r
43 # Awaken mail process\r
44 m = mmap.mmap(-1, 1, sys.argv[1])\r
45 m[0] = '1'\r
46\r
47 # Do nothing but wait for the signal\r
48 while True:\r
49 pass\r