Part of lp.services.command_spawner View In Hierarchy
Lets you run commands in sub-processes that will run simulaneously. The CommandSpawner looks for output from the running processes, and manages their cleanup.
The typical usage pattern is:
>>> spawner = CommandSpawner() >>> spawner.start(["echo", "One parallel process"]) >>> spawner.start(["echo", "Another parallel process"]) >>> spawner.complete()
There are facilities for processing output and error output from the
sub-processes, as well as dealing with success and failure. You can
pass callbacks to the
start method, to be called when these events
As yet there is no facility for feeding input to the processes.
|Method||communicate||Execute one iteration of the main event loop. Blocks.|
|Method||kill||Kill any remaining child processes.|
|Method||_spawn||Spawn a sub-process for
|Method||_handle||If we have a handler for
|Method||_read||Read output from
commandin a sub-process.
This starts the command, but does not wait for it to complete. Instead of waiting for completion, you can pass handlers that will be called when certain events occur.
|Parameters||command||Command line to execute in a sub-process. May be either a string (for a single executable name) or a list of strings (for an executable name plus arguments).|
|stdout_handler||Callback to handle output received from the sub-process. Must take the output as its sole argument. May be called any number of times as output comes in.|
|stderr_handler||Callback to handle error output received from the sub-process. Must take the output as its sole argument. May be called any number of times as output comes in.|
|completion_handler||Callback to be invoked, exactly once, when
the sub-process exits. Must take |
You'll still need to call
complete to make sure that the child
processes are cleaned up. Until then, they will stay around as
process, call it.