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 ametatheton2, eryksun, gvanrossum, paul.moore, steve.dower, tim.golden, zach.ware
Date 2021-01-18.22:38:05
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1611009485.33.0.344577705382.issue42959@roundup.psfhosted.org>
In-reply-to
Content
FYI, Windows is not a POSIX operating system and does not implement Unix signals in the kernel. That said, the C language serves as a base level of cross-platform support for language runtimes across most operating systems, and there's significant coupling between C and Unix. Standard C requires six Unix signals to be supported in some fashion: SIGABRT, SIGTERM, SIGFPE, SIGILL, SIGSEGV, and SIGINT. 

The C runtime in Windows implements SIGABRT and SIGTERM only within the process, e.g. with C raise() and abort(). There's no mechanism to send these signals to another process. It implements SIGFPE, SIGILL, SIGSEGV using an OS structured exception handler, but these can't and shouldn't be handled in Python. 

That leaves SIGINT, which is implemented for console applications using a console control handler for the cancel event (CTRL_C_EVENT). The same handler also implements non-standard SIGBREAK for the other console control events: break, close, logoff, and shutdown. 

There's limited support to send the cancel and break events (CTRL_C_EVENT and CTRL_BREAK_EVENT) to other processes via WinAPI GenerateConsoleCtrlEvent(ctrlEvent, processGroupId). The event can be sent to a process group in the current console session or to all processes (group 0) in the console session. The process group ID (pgid) of a process cannot be directly queried. The only way to know a pgid is to create a process as the leader of a new group with the creation flag CREATE_NEW_PROCESS_GROUP, in which case the pgid is the pid. A new process group initially has the cancel event ignored, until a process manually enables it. So in practice you can only rely on sending the break event. This is implemented in Python via os.kill(pgid, event) and subprocess.Popen.send_signal(event). But remember the target pgid must be either 0 or a known pgid. Using a pid that's not a pgid has undefined behavior.
History
Date User Action Args
2021-01-18 22:38:05eryksunsetrecipients: + eryksun, gvanrossum, paul.moore, tim.golden, zach.ware, steve.dower, ametatheton2
2021-01-18 22:38:05eryksunsetmessageid: <1611009485.33.0.344577705382.issue42959@roundup.psfhosted.org>
2021-01-18 22:38:05eryksunlinkissue42959 messages
2021-01-18 22:38:05eryksuncreate