pyfarm.jobtypes.core.process module

Process

Module responsible for connecting a Twisted process object and a job type. Additionally this module contains other classes which are useful in starting or managing a process.

class pyfarm.jobtypes.core.process.ReplaceEnvironment(frozen_environment, environment=None)[source]

Bases: object

A context manager which will replace os.environ’s, or dictionary of your choosing, for a short period of time. After exiting the context manager the original environment will be restored.

This is useful if you have something like a process that’s using global environment and you want to ensure that global environment is always consistent.

Parameters:environment (dict) – If provided, use this as the environment dictionary instead of os.environ
class pyfarm.jobtypes.core.process.ProcessProtocol(jobtype)[source]

Bases: twisted.internet.protocol.ProcessProtocol

Subclass of Protocol which hooks into the various systems necessary to run and manage a process. More specifically, this helps to act as plumbing between the process being run and the job type.

uuid
pid
process

The underlying Twisted process object

psutil_process

Returns a psutil.Process object for the running process

connectionMade()[source]

Called when the process first starts and the file descriptors have opened.

processEnded(reason)[source]

Called when the process has terminated and all file descriptors have been closed. processExited() is called, too, however we only want to notify the parent job type once the process has freed up the last bit of resources.

outReceived(data)[source]

Called when the process emits on stdout

errReceived(data)[source]

Called when the process emits on stderr

kill()[source]

Kills the underlying process, if running.

terminate()[source]

Terminates the underlying process, if running.

interrupt()[source]

Interrupts the underlying process, if running.

running()[source]

Method to determine whether the child process is currently running