[issue19843] Wait for multiple sub-processes to terminate

Giampaolo Rodola' report at bugs.python.org
Sat Nov 30 16:53:33 CET 2013


New submission from Giampaolo Rodola':

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?

----------
files: wait_procs.patch
keywords: patch
messages: 204824
nosy: giampaolo.rodola
priority: normal
severity: normal
status: open
title: Wait for multiple sub-processes to terminate
versions: Python 3.4
Added file: http://bugs.python.org/file32912/wait_procs.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue19843>
_______________________________________


More information about the Python-bugs-list mailing list