ProcessMonitor runs processes, monitors their progress, and restarts them when they die.

The ProcessMonitor will not attempt to restart a process that appears to die instantly -- with each "instant" death (less than 1 second, by default), it will delay approximately twice as long before restarting it. A successful run will reset the counter.

The primary interface is addProcess and removeProcess. When the service is running (that is, when the application it is attached to is running), adding a process automatically starts it.

Each process has a name. This name string must uniquely identify the process. In particular, attempting to add two processes with the same name will result in a KeyError.

Instance Variable threshold How long a process has to live before the death is considered instant, in seconds. The default value is 1 second. (type: float)
Instance Variable killTime How long a process being killed has to get its affairs in order before it gets killed with an unmaskable signal. The default value is 5 seconds. (type: float)
Instance Variable minRestartDelay The minimum time (in seconds) to wait before attempting to restart a process. Default 1s. (type: float)
Instance Variable maxRestartDelay The maximum time (in seconds) to wait before attempting to restart a process. Default 3600s (1h). (type: float)
Method __init__ Undocumented
Method __getstate__ Undocumented
Method addProcess Add a new monitored process and start it immediately if the ProcessMonitor service is running.
Method removeProcess Stop the named process and remove it from the list of monitored processes.
Method startService Start all monitored processes.
Method stopService Stop all monitored processes and cancel all scheduled process restarts.
Method connectionLost No summary
Method startProcess
Method stopProcess
Method restartAll No summary
Method __repr__ Undocumented
Instance Variable _reactor A provider of IReactorProcess and IReactorTime which will be used to spawn processes and register delayed calls. (type: IReactorProcess provider)
Method _forceStopProcess

Inherited from Service:

Method setName Set the name of the service.
Method setServiceParent Set the parent of the service. This method is responsible for setting the parent attribute on this service (the child service).
Method disownServiceParent Use this API to remove an IService from an IServiceCollection.
Method privilegedStartService Do preparation work for starting the service.
threshold =
How long a process has to live before the death is considered instant, in seconds. The default value is 1 second. (type: float)
killTime =
How long a process being killed has to get its affairs in order before it gets killed with an unmaskable signal. The default value is 5 seconds. (type: float)
minRestartDelay =
The minimum time (in seconds) to wait before attempting to restart a process. Default 1s. (type: float)
maxRestartDelay =
The maximum time (in seconds) to wait before attempting to restart a process. Default 3600s (1h). (type: float)
_reactor =
A provider of IReactorProcess and IReactorTime which will be used to spawn processes and register delayed calls. (type: IReactorProcess provider)
def __init__(self, reactor=_reactor): (source)
Undocumented
def __getstate__(self): (source)
def addProcess(self, name, args, uid=None, gid=None, env={}): (source)

Add a new monitored process and start it immediately if the ProcessMonitor service is running.

Note that args are passed to the system call, not to the shell. If running the shell is desired, the common idiom is to use ProcessMonitor.addProcess("name", ['/bin/sh', '-c', shell_script])

ParametersnameA name for this process. This value must be unique across all processes added to this monitor. (type: str)
argsThe argv sequence for the process to launch.
uidThe user ID to use to run the process. If None, the current UID is used. (type: int)
gidThe group ID to use to run the process. If None, the current GID is used.
envThe environment to give to the launched process. See IReactorProcess.spawnProcess's env parameter. (type: dict)
RaisesKeyError if a process with the given name already exists
def removeProcess(self, name): (source)

Stop the named process and remove it from the list of monitored processes.

ParametersnameA string that uniquely identifies the process. (type: str)
def startService(self): (source)
def stopService(self): (source)

Stop all monitored processes and cancel all scheduled process restarts.

def connectionLost(self, name): (source)

Called when a monitored processes exits. If service.IService.running is True (ie the service is started), the process will be restarted. If the process had been running for more than ProcessMonitor.threshold seconds it will be restarted immediately. If the process had been running for less than ProcessMonitor.threshold seconds, the restart will be delayed and each time the process dies before the configured threshold, the restart delay will be doubled - up to a maximum delay of maxRestartDelay sec.

ParametersnameA string that uniquely identifies the process which exited. (type: str)
def startProcess(self, name): (source)
ParametersnameThe name of the process to be started
def _forceStopProcess(self, proc): (source)
ParametersprocAn IProcessTransport provider
def stopProcess(self, name): (source)
ParametersnameThe name of the process to be stopped
def restartAll(self): (source)

Restart all processes. This is useful for third party management services to allow a user to restart servers because of an outside change in circumstances -- for example, a new version of a library is installed.

def __repr__(self): (source)
Undocumented
API Documentation for Twisted, generated by pydoctor at 2017-06-11 10:59:01.