[New-bugs-announce] [issue11361] suggestion for os.kill(pid, CTRL_C_EVENT)

Igor report at bugs.python.org
Tue Mar 1 14:30:21 CET 2011

New submission from Igor <igor at prettysin.info>:


I see some 'skip' in test_os.py

    @unittest.skip("subprocesses aren't inheriting CTRL+C property")
    def test_CTRL_C_EVENT(self):

I think, problem with calling SetConsoleCtrlHandler(NULL,0) in parent process, rather in child. If call SetConsoleCtrlHandler(NULL, 0).

Calling SetConsoleCtrlHandler(ctrl_handler, 1) is not enough. Need first call SetConsoleCtrlHandler(NULL, 0).

My patch for this test fixture: (may be, not so good, but it works)

H:\usr\python27\Lib\test>diff win_console_handler.py win_console_handler.py_orig

<     elif sig == signal.SIGINT:
<         pass
< def ctrl_handler_int(sig, obj):
<     sys.exit(1)
< NULL = ctypes.POINTER(ctypes.c_int)()
<     # 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.B
<     if not SetConsoleCtrlHandler(NULL, 0):
<         print("Unable to restore SetConsoleCtrlHandler")
<         exit(-1)
<     signal.signal(signal.SIGINT, ctrl_handler_int)
<     SetConsoleCtrlHandler.argtypes = (HandlerRoutine, wintypes.BOOL)

And on my machine  (win2003 32bit):
test_CTRL_BREAK_EVENT (__main__.Win32KillTests) ... ok
test_CTRL_C_EVENT (__main__.Win32KillTests) ... ok
test_kill_int (__main__.Win32KillTests) ... ok
test_kill_sigterm (__main__.Win32KillTests) ... ok

Ran 61 tests in 2.344s


components: IO
messages: 129761
nosy: iigor
priority: normal
severity: normal
status: open
title: suggestion for os.kill(pid,CTRL_C_EVENT)
type: behavior
versions: Python 2.7

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list