l.s.t.p.ProcessMonitorProtocol(ProcessProtocolWithTwoStageKill) : class documentation

Part of lp.services.twistedsupport.processmonitor View In Hierarchy

Known subclasses: lp.services.twistedsupport.processmonitor.ProcessMonitorProtocolWithTimeout

Support for running a process and reporting on its progress.

The idea is this: you want to run a child process. Occasionally, you want to report on what it is doing to some other entity: maybe it's a multistep task and you want to update a row in a database to reflect which step it is currently on. This class provides a runNotification() method that helps with this, taking a callable that performs this notfication, maybe returning a deferred.

Design decisions:

Instance Variables_deferredThe deferred that will be fired when the child process exits.
_notification_lockA DeferredLock, used to serialize the notifications.
_termination_failureWhen we kill the child process in response to some unexpected error, we report the reason we killed it to self._deferred, not that it exited because we killed it.
Method __init__ Construct an instance of the protocol, for listening to a worker.
Method runNotification Run a given function in series with other notifications.
Method unexpectedError Something's gone wrong: kill the subprocess and report failure.
Method processEnded See ProcessProtocol.processEnded.

Inherited from ProcessProtocolWithTwoStageKill:

Method terminateProcess Terminate the process by SIGINT initially, but SIGKILL if needed.
Method _sigkill Forcefully kill the process.
def __init__(self, deferred, clock=None):
Construct an instance of the protocol, for listening to a worker.
ParametersdeferredA Deferred that will be fired when the subprocess has finished (either successfully or unsuccesfully).
def runNotification(self, func, *args):
Run a given function in series with other notifications.

"func(*args)" will be called when any other running or queued
notifications have completed.  func() may return a Deferred.  Note
that if func() errors out, this is considered a fatal error and the
subprocess will be killed.
def unexpectedError(self, failure):
Something's gone wrong: kill the subprocess and report failure.

Note that we depend on terminateProcess() killing the process: we depend on the fact that processEnded will be called after calling it.

def processEnded(self, reason):
See ProcessProtocol.processEnded.

We fire the termination deferred, after waiting for any in-progress notifications to complete.

API Documentation for Launchpad, generated by pydoctor at 2018-02-25 00:00:04.