--- Lib/tests/test_os.py_orig Sat Nov 27 15:26:02 2010 +++ Lib/tests/test_os.py Tue Mar 01 15:38:27 2011 @@ -768,7 +768,7 @@ os.kill(proc.pid, signal.SIGINT) self.fail("subprocess did not stop on {}".format(name)) - @unittest.skip("subprocesses aren't inheriting CTRL+C property") +# @unittest.skip("subprocesses aren't inheriting CTRL+C property") def test_CTRL_C_EVENT(self): from ctypes import wintypes import ctypes --- Lib/tests/win_console_handler.py_orig Sat Nov 13 20:08:20 2010 +++ Lib/tests/win_console_handler.py Tue Mar 01 15:58:45 2011 @@ -23,23 +23,38 @@ pass elif sig == signal.CTRL_BREAK_EVENT: pass + elif sig == signal.SIGINT: + pass else: print("UNKNOWN EVENT") return 0 ctrl_handler = HandlerRoutine(_ctrl_handler) +def ctrl_handler_int(sig, obj): + sys.exit(1) SetConsoleCtrlHandler = ctypes.windll.kernel32.SetConsoleCtrlHandler SetConsoleCtrlHandler.argtypes = (HandlerRoutine, wintypes.BOOL) SetConsoleCtrlHandler.restype = wintypes.BOOL +NULL = ctypes.POINTER(ctypes.c_int)() if __name__ == "__main__": + # Calling this with NULL and FALSE causes the calling process to + # handle CTRL+C, rather than ignore it. This property isn't inherited + # by subprocesses, if it's created with CREATE_NEW_PROCESS_GROUP flag + SetConsoleCtrlHandler.argtypes = (ctypes.POINTER(ctypes.c_int), wintypes.BOOL) + if not SetConsoleCtrlHandler(NULL, 0): + print("Unable to restore SetConsoleCtrlHandler") + exit(-1) + + signal.signal(signal.SIGINT, ctrl_handler_int) + + SetConsoleCtrlHandler.argtypes = (HandlerRoutine, wintypes.BOOL) # Add our console control handling function with value 1 if not SetConsoleCtrlHandler(ctrl_handler, 1): print("Unable to add SetConsoleCtrlHandler") exit(-1) - # Awaken mail process m = mmap.mmap(-1, 1, sys.argv[1]) m[0] = '1'