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.
Created on 2009年01月31日 02:50 by erickt, last changed 2022年04月11日 14:56 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| killpg.patch | erickt, 2009年01月31日 02:50 | review | ||
| Messages (8) | |||
|---|---|---|---|
| msg80850 - (view) | Author: Erick Tryzelaar (erickt) | Date: 2009年01月31日 02:50 | |
It would be really handy to add a way to portably kill process groups of a process spawned with subprocess.Popen. My project starts a process, which then starts other long running processes. Because of this process tree, there's no way for me to portably kill all of those processes. Would it be possible to extend subprocess with these features? I did find someone who's already implemented this [1], and it's working well in my project. There was some discussion about adding this, but it seems no one actually committed a patch to implement it. Anyway, I've attached a patch against python3.0's svn branch that implements this. I don't have access to windows, so I'm not able to make sure that the TerminateJobObject is correct, and works. [1]: http://benjamin.smedbergs.us/blog/2006-12-11/killableprocesspy/ [2]: http://mail.python.org/pipermail/python-list/2008-April/487588.html |
|||
| msg81076 - (view) | Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) | Date: 2009年02月03日 18:07 | |
I suspect that on Windows, TerminateJobObject won't work with a handle returned by CreateProcess. A solution could look like http://www.mobzystems.com/code/killprocesstree.aspx |
|||
| msg98087 - (view) | Author: STINNER Victor (vstinner) * (Python committer) | Date: 2010年01月21日 00:29 | |
> I suspect that on Windows, TerminateJobObject won't work > with a handle returned by CreateProcess. TerminateJobObject works with CreateJobObject and AssignProcessToJobObject. The following code (from your patch) should call AssignProcessToJobObject (and CreateJobObject if there is no job yet): + if not mswindows: + os.setpgid(0, 0) |
|||
| msg107615 - (view) | Author: STINNER Victor (vstinner) * (Python committer) | Date: 2010年06月12日 00:22 | |
erickt: can you fix your patch? |
|||
| msg108062 - (view) | Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) | Date: 2010年06月17日 21:10 | |
A strong +1 on adding this feature. I was wondering... what if process A runs a subprocess B which runs a subprocess C. Is C still considered a children of A and gets killed as well? Does os.setpgid() takes care of such a thing? What about Windows instead? |
|||
| msg134500 - (view) | Author: Charles-François Natali (neologix) * (Python committer) | Date: 2011年04月26日 21:09 | |
Note that the setpgid creation part is now somewhat redundant with Popen's start_new_session flag (which calls setsid). Also, this should probably be an option, since with that patch every subprocess is in its own process group. > I was wondering... what if process A runs a subprocess B which runs a > subprocess C. Is C still considered a children of A and gets killed as > well? No. When setpgid/setsid is called, a new group is created, so process C will be not be part of the same group as B. |
|||
| msg292233 - (view) | Author: Eryk Sun (eryksun) * (Python triager) | Date: 2017年04月24日 18:30 | |
Using a Windows job object should be paired with the creation flag CREATE_SUSPENDED. Callers may also need CREATE_BREAKAWAY_FROM_JOB, but setting that creation flag shouldn't be integrated into Popen. The child has to be created suspended to ensure it doesn't spawn another process and exit before it's added to the job. Once it's in the job, call ResumeThread to start it. On Windows Vista and 7, the child may need to break away from Python's current job, if allowed. These older versions of Windows don't implement nested jobs, so adding the child to a job will fail if it's already in one. The job used by py.exe for python.exe isn't a problem in this case since it's configured for child processes to automatically break away, but python.exe may have been started directly and added to a job that's not configured for silent breakaway. |
|||
| msg346945 - (view) | Author: Gregory P. Smith (gregory.p.smith) * (Python committer) | Date: 2019年07月01日 00:06 | |
this is part of a chain of other related issues. the interesting thing in the patch in here is the potential feature to have send_signal/terminate/kill be able to optionally kill a process group. the logic as is in the patch in this issue is dangerous as often the calling process _is_ the pgrp leader and would be killed. we _never_ want the subprocess signaling methods to kill the current process as that would be surprising to users. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:56:45 | admin | set | github: 49365 |
| 2019年07月01日 00:06:10 | gregory.p.smith | set | status: open -> closed nosy: + gregory.p.smith messages: + msg346945 stage: patch review -> resolved |
| 2019年07月01日 00:04:26 | gregory.p.smith | set | superseder: subprocess.run timeout does not function if shell=True and capture_output=True resolution: duplicate |
| 2019年06月30日 22:55:07 | gregory.p.smith | set | pull_requests: - pull_request7893 |
| 2019年06月27日 13:20:42 | haizaar | set | nosy:
+ haizaar |
| 2018年07月20日 20:26:43 | ammar2 | set | pull_requests: + pull_request7893 |
| 2018年02月16日 13:03:38 | fangyizhou | set | nosy:
+ fangyizhou |
| 2017年04月24日 18:30:07 | eryksun | set | nosy:
+ eryksun messages: + msg292233 versions: + Python 3.7, - Python 3.3 |
| 2017年04月24日 11:47:07 | martin.panter | link | issue26534 dependencies |
| 2011年04月26日 21:09:52 | neologix | set | nosy:
+ neologix messages: + msg134500 |
| 2011年04月26日 15:01:49 | xuanji | set | nosy:
+ xuanji |
| 2011年04月18日 13:06:25 | giampaolo.rodola | set | versions: + Python 3.3, - Python 3.0 |
| 2011年04月18日 13:01:55 | Ernst.Sjöstrand | set | nosy:
+ Ernst.Sjöstrand |
| 2010年06月17日 21:10:58 | giampaolo.rodola | set | messages: + msg108062 |
| 2010年06月12日 00:22:40 | vstinner | set | messages: + msg107615 |
| 2010年06月09日 17:45:29 | giampaolo.rodola | set | nosy: guettli, amaury.forgeotdarc, vstinner, giampaolo.rodola, erickt, brian.curtin |
| 2010年01月21日 00:29:30 | vstinner | set | nosy:
+ vstinner messages: + msg98087 |
| 2010年01月20日 11:49:07 | guettli | set | nosy:
+ guettli |
| 2010年01月13日 02:03:33 | brian.curtin | set | priority: normal stage: patch review |
| 2009年12月31日 01:25:04 | brian.curtin | set | nosy:
+ brian.curtin |
| 2009年02月03日 18:07:02 | amaury.forgeotdarc | set | nosy:
+ amaury.forgeotdarc messages: + msg81076 |
| 2009年01月31日 19:54:15 | giampaolo.rodola | set | nosy: + giampaolo.rodola |
| 2009年01月31日 02:50:59 | erickt | create | |