Eryk Sun <eryk...@gmail.com> added the comment:

The signal.signal() docs should explain that only SIGINT and SIGBREAK can be 
signaled from another process, and only if the current process is a console 
application. A link to os.kill() could be added, which should explain their use 
as signals in relation to console control events. Also, setting a handler for 
SIGABRT, SIGFPE, SIGILL, and SIGSEGV should be discouraged in the documentation 
because they are not compatible with how Python handles signals by tripping a 
flag for deferred processing on the main thread.

The design of os.kill() in Windows has some unfortunate mistakes, but it needs 
to be better documented at least. It should explain that the pid value, when 
used with CTRL_C_EVENT and CTRL_BREAK_EVENT, is a process-group ID, not a 
process ID. It should explain that CTRL_C_EVENT will be ignored by a process in 
the target group if the process calls SetConsoleCtrlHandler(NULL, TRUE), or if 
it's started with Ctrl+C ignored either due to inheritance or due to being 
created in a new process group. It should explain that these console control 
events get mapped to the C signals SIGINT and SIGBREAK. 

Also the line "[t]he Windows version of kill() additionally takes process 
handles to be killed" needs to removed. os.kill() has never accepted handles in 
addition to PIDs. Implementing that reliably would require an additional 
parameter.

---

Ideally, the code path in os.kill() that generates a console control event 
would have been reserved for a negative PID value (i.e. a process group ID), 
with -1 reserved to send the event to all processes in the console session 
(i.e. console process group 0). Also, in this case, os.kill() would use SIGINT 
and SIGBREAK instead of WinAPI CTRL_C_EVENT and CTRL_BREAK_EVENT. Such a design 
would have conformed much better with POSIX kill().

----------
components: +Extension Modules, Windows
nosy: +eric.araujo, ezio.melotti, mdk, paul.moore, steve.dower, tim.golden, 
willingc, zach.ware
stage:  -> needs patch
title: Windows: signal doc should state certains signals can't be registered -> 
[Windows] signal.signal and os.kill doc should better explain what is supported
type:  -> enhancement
versions: +Python 3.10, Python 3.8, Python 3.9

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue26350>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to