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: Wait for multiple sub-processes to terminate
Type: enhancement Stage: patch review
Components: Versions: Python 3.5
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: giampaolo.rodola, gregory.p.smith, r.david.murray
Priority: normal Keywords: patch

Created on 2013-11-30 15:53 by giampaolo.rodola, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
wait_procs.patch giampaolo.rodola, 2013-11-30 15:53 review
Messages (5)
msg204824 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2013-11-30 15:53
I recently implemented this in psutil and thought it would have been a nice addition for subprocess module as well:
https://code.google.com/p/psutil/issues/detail?id=440

Patch in attachment introduces a new subprocess.wait_procs() utility function which waits for multiple processes (Popen instances) to terminate.
The use case this covers is quote common: send SIGTERM to a list of processes, wait for them to terminate, send SIGKILL as last resort:


>>> def on_terminate(proc):
...     print("process {} terminated".format(proc))
...
>>> for p in procs:
...    p.terminate()
...
>>> gone, still_alive = wait_procs(procs, timeout=3, callback=on_terminate)
>>> for p in still_alive:
...     p.kill()


Are we still in time for Python 3.4?
msg204838 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2013-11-30 19:02
It's not, the beta is already out.
msg205482 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2013-12-07 20:13
I do not think this is ready to live in the standard library.  

I've left some comments on your patch review.  Consider those for incorporation into the psutils project.

wait_procs() implementation should live in the psutils module on PyPI with more iteration on its implementation happening there as it isn't ready yet.

In general: We have too many APIs in the subprocess module.  I want to avoid adding more unless they are a very clear improvement to ease of use of the module.  More things with deadlock caveats similar to the existing Popen.wait() call are undesirable.
msg205687 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2013-12-09 13:15
I replied to your comments here:
http://bugs.python.org/review/19843/
Assuming the deadlock problem gets fixed would you consider this feature worthy for inclusion?
msg207313 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2014-01-04 21:48
I'd rather see it bake in psutils for a while longer regardless of implementation.
History
Date User Action Args
2022-04-11 14:57:54adminsetgithub: 64042
2014-01-04 21:48:12gregory.p.smithsetmessages: + msg207313
2013-12-09 13:15:59giampaolo.rodolasetmessages: + msg205687
2013-12-07 20:13:43gregory.p.smithsetstatus: open -> closed

type: enhancement

nosy: + gregory.p.smith
messages: + msg205482
resolution: rejected
stage: patch review
2013-11-30 19:02:14r.david.murraysetnosy: + r.david.murray

messages: + msg204838
versions: + Python 3.5, - Python 3.4
2013-11-30 15:53:33giampaolo.rodolacreate