This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eryksun
Recipients brian.curtin, eryksun, iigor, vstinner
Date 2015-12-05.19:13:25
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1449342805.86.0.409191646891.issue11361@psf.upfronthosting.co.za>
In-reply-to
Content
test_CTRL_C_EVENT can be removed from Lib/test/test_os.py. It's of no practical consequence. Ctrl+Break is always enabled in the child process, so test_CTRL_BREAK_EVENT should remain.

When using CREATE_NEW_PROCESS_GROUP, the child process is started with Ctrl+C disabled. Whether or not Ctrl+C is enabled in the parent process is irrelevant. 

An example that shows the intent of this creation flag is the /B (background) option of the cmd shell's "start" command. Ctrl+C from the user shouldn't interrupt such programs, so "start /B" uses the CREATE_NEW_PROCESS_GROUP creation flag. You can still kill the process with Ctrl+Break, assuming it hasn't installed a control handler that ignores CTRL_BREAK_EVENT instead of chaining to the default handler. 

For example:

    C:\>start /b /w py -3
    Python 3.5.0 (v3.5.0:374f501f4567, Sep 13 2015, 02:27:37)
    [MSC v.1900 64 bit (AMD64)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import os
    >>> import time
    >>> import signal
    >>> import ctypes
    >>>
    >>> _ = signal.signal(signal.SIGINT, lambda *a: print('^C'))
    >>> _ = signal.signal(signal.SIGBREAK, lambda *a: print('^BREAK'))
    >>>
    >>> def test_ctrl_event(event):
    ...     os.kill(os.getpid(), event)
    ...     time.sleep(1)
    ...

    >>> test_ctrl_event(signal.CTRL_BREAK_EVENT) # works
    ^BREAK
    >>> test_ctrl_event(signal.CTRL_C_EVENT) # nothing

As this issue notes, the child process can use ctypes to manually enable Ctrl+C events for the current process:

    >>> ctypes.windll.kernel32.SetConsoleCtrlHandler(None, 0)
    1
    >>> test_ctrl_event(signal.CTRL_C_EVENT) # works
    ^C

But this is contrived. You rarely have such control over the child process unless it's your own code, in which case there are far better IPC mechanisms available than to rely on the console host process (conhost.exe) as th arbiter of communication.
History
Date User Action Args
2015-12-05 19:13:25eryksunsetrecipients: + eryksun, vstinner, brian.curtin, iigor
2015-12-05 19:13:25eryksunsetmessageid: <1449342805.86.0.409191646891.issue11361@psf.upfronthosting.co.za>
2015-12-05 19:13:25eryksunlinkissue11361 messages
2015-12-05 19:13:25eryksuncreate