classification
Title: Possible problem in documentation of module subprocess, method send_signal
Type: behavior Stage: needs patch
Components: Documentation, Windows Versions: Python 3.3, Python 3.2, Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: brian.curtin Nosy List: brian.curtin, docs@python, eli.bendersky
Priority: normal Keywords:

Created on 2011-11-08 03:23 by eli.bendersky, last changed 2011-11-11 14:19 by brian.curtin.

Messages (3)
msg147272 - (view) Author: Eli Bendersky (eli.bendersky) * (Python committer) Date: 2011-11-08 03:23
docs@ list report by Daniel Dieterle:

in the documentation (http://docs.python.org/library/subprocess.html#subprocess.Popen.send_signal) is a bug.

CTRL_C_EVENT can not be sent to processes started with a creationflags parameter which includes CREATE_NEW_PROCESS_GROUP. Why can be read in the msdn documentation http://msdn.microsoft.com/en-us/library/windows/desktop/ms683155%28v=vs.85%29.aspx .

A workaround using CTRL_C_EVENT nevertheless is described here:
http://stackoverflow.com/questions/7085604/sending-c-to-python-subprocess-objects-on-windows/7980368#7980368 

--

I do not know why the subprocess.CREATE_NEW_PROCESS_GROUP parameter was introduced. But it is useless for terminating a process with os.kill() in combination with signal.SIGTERM, which corresponds to a CTRL-C-EVENT.
A CTRL-C-EVENT is only forwarded to the process if the process group is zero. Therefore the Note in the documentation on Popen.send_signal() is wrong.
msg147425 - (view) Author: Eli Bendersky (eli.bendersky) * (Python committer) Date: 2011-11-11 09:24
Brian, I see this text (along with the implementation) was added by you in  60197:0ab89e8bdedc

Could you state your opinion on this issue?
msg147432 - (view) Author: Brian Curtin (brian.curtin) * (Python committer) Date: 2011-11-11 14:19
> But it is useless for terminating a process with os.kill() in combination with signal.SIGTERM, which corresponds to a CTRL-C-EVENT.

SIGTERM does not correspond to CTRL_C_EVENT. They may be similar in what they do, but os.kill on Windows only works with exactly CTRL_C_EVENT and CTRL_BREAK_EVENT, as this uses GenerateConsoleCtrlEvent which only works with those two values. As the documentation states, anything other than those two constants is sent to TerminateProcess. If you call os.kill with signal.SIGTERM, it would kill the process with return code 15.



I will look into adjusting the text a little, and I also need to look into the tests. I currently have CTRL_C_EVENT tests skipped, probably because I am passing the wrong process stuff as he mentioned. I had it working at some point, but I may have generalized it too far.
History
Date User Action Args
2011-11-11 14:19:25brian.curtinsetversions: + Python 3.2, Python 3.3
messages: + msg147432

assignee: docs@python -> brian.curtin
components: + Windows
type: behavior
stage: needs patch
2011-11-11 09:24:06eli.benderskysetnosy: + brian.curtin
messages: + msg147425
2011-11-08 03:23:14eli.benderskycreate