[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>:

Hello!

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

26,27d25
<     elif sig == signal.SIGINT:
<         pass
34,35d31
< def ctrl_handler_int(sig, obj):
<     sys.exit(1)
40d35
< NULL = ctypes.POINTER(ctypes.c_int)()
43,53d37
<     # 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
OOL)
<     if not SetConsoleCtrlHandler(NULL, 0):
<         print("Unable to restore SetConsoleCtrlHandler")
<         exit(-1)
<
<     signal.signal(signal.SIGINT, ctrl_handler_int)
<
<     SetConsoleCtrlHandler.argtypes = (HandlerRoutine, wintypes.BOOL)
57a42
>

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

OK

----------
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>
<http://bugs.python.org/issue11361>
_______________________________________


More information about the Python-bugs-list mailing list