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.

classification
Title: os.kill on Windows should accept zero as signal
Type: enhancement Stage: needs patch
Components: Library (Lib), Windows Versions: Python 3.3
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: asvetlov, brian.curtin, giampaolo.rodola, r.david.murray, vstinner
Priority: normal Keywords: easy

Created on 2012-04-03 07:23 by asvetlov, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (6)
msg157398 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2012-04-03 07:23
Starting from 3.2 Python supports os.kill for Windows.
It process signal.CTRL_C_EVENT and signal.CTRL_BREAK_EVENT, and kills pid for all other signals.

Posix allows to pass zero signal to check pid for existing.
It will be nice to keep that behavior for Windows also.
The patch should be trivial: just don't call TerminateProcess in Modules/posixmodule.c:win32_kill if sig is zero.
msg157418 - (view) Author: Brian Curtin (brian.curtin) * (Python committer) Date: 2012-04-03 14:08
-1

0 has no special meaning on Windows so I'd rather not add another special case for posix emulation. Additionally, 0 unfortunately already means two things as it is: signal.CTRL_C_EVENT and the int 0.
msg157425 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2012-04-03 14:35
Hmm.  I would think it would be a good idea to have os.kill do posix emulation where that makes sense, it makes cross-platform usage easier.  That's what 'kill' with no signal does, right (kills the process, just like the posix default)?

The posix spec says "If sig is 0 (the null signal), error checking is performed but no signal is actually sent. The null signal can be used to check the validity of pid." So *signal* zero doesn't have any special meaning on posix, either, but it does have a special meaning to the kill command.

It seems like it would be nice to add support for that to the windows version, but I'm a little confused.  First you say that signal 0 has no special meaning, and then you say that it does (signal.CTRL_C_EVENT).  Which is it?
msg157427 - (view) Author: Brian Curtin (brian.curtin) * (Python committer) Date: 2012-04-03 14:43
I meant that in the underlying, such as in the TerminateProcess API, 0 doesn't mean anything special. As is being debated over on #14484 we currently take all integers to be passed to TerminateProcess (the int becomes the killed proc's return code), and two signals to pass to GenerateConsoleCtrlEvent (which is more like posix os.kill).
msg157430 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2012-04-03 15:09
There are no `kill` function in Windows API.
From my perspective win32_kill was added to emulate posix sibling if possible. If not — better to give another Windows native name to that function.
Really don't see good solution. Maybe better what we can do — declare what os.kill cannot be called with 0 signum on Windows for proc presence checking and note that fact in os.rst.
Terminating process looks like overcomplication. POSIX kill only sends signal to process and nothing more.
msg238654 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2015-03-20 12:26
> 0 has no special meaning on Windows so I'd rather not add another special case for posix emulation. Additionally, 0 unfortunately already means two things as it is: signal.CTRL_C_EVENT and the int 0.

I agree, it's not a good idea to support os.kill(pid, 0) on Windows. I reject the issue.

See also the issue #14484.
History
Date User Action Args
2022-04-11 14:57:28adminsetgithub: 58685
2015-03-20 12:26:30vstinnersetstatus: open -> closed

nosy: + vstinner
messages: + msg238654

resolution: rejected
2014-01-18 01:43:59giampaolo.rodolasetnosy: + giampaolo.rodola
2012-04-03 15:09:18asvetlovsetmessages: + msg157430
2012-04-03 14:43:06brian.curtinsetmessages: + msg157427
2012-04-03 14:35:12r.david.murraysetstatus: pending -> open
nosy: + r.david.murray
messages: + msg157425

2012-04-03 14:08:13brian.curtinsetstatus: open -> pending

messages: + msg157418
2012-04-03 11:33:45r.david.murraysetnosy: + brian.curtin

type: behavior -> enhancement
stage: needs patch
2012-04-03 07:23:13asvetlovcreate