l.s.c.CommandSpawner : class documentation

Part of lp.services.command_spawner View In Hierarchy

Simple manager to execute commands in parallel.

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 occur.

As yet there is no facility for feeding input to the processes.

Method __init__ Undocumented
Method start Run command in a sub-process.
Method communicate Execute one iteration of the main event loop. Blocks.
Method complete Run self.communicate until all sub-processes have completed.
Method kill Kill any remaining child processes.
Method _spawn Spawn a sub-process for command. Overridable in tests.
Method _handle If we have a handler for event on process, call it.
Method _read Read output from pipe_file.
Method _service Service process.
def __init__(self):
Undocumented
def start(self, command, stdout_handler=None, stderr_handler=None, completion_handler=None):
Run command in 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.

ParameterscommandCommand 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_handlerCallback 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_handlerCallback 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_handlerCallback to be invoked, exactly once, when the sub-process exits. Must take command's numeric return code as its sole argument.
def communicate(self):
Execute one iteration of the main event loop. Blocks.
def complete(self):
Run self.communicate until all sub-processes have completed.
def kill(self):
Kill any remaining child processes.

You'll still need to call complete to make sure that the child processes are cleaned up. Until then, they will stay around as zombies.

def _spawn(self, command):
Spawn a sub-process for command. Overridable in tests.
def _handle(self, process, event, *args):
If we have a handler for event on process, call it.
def _read(self, process, pipe_file, event):
Read output from pipe_file.
def _service(self, process, events_by_fd):
Service process.
API Documentation for Launchpad, generated by pydoctor at 2018-08-20 00:00:04.