class documentation

class Process(_pollingfile._PollingTimer, BaseProcess): (source)

Implements interfaces: twisted.internet.interfaces.IConsumer, twisted.internet.interfaces.IProcessTransport, twisted.internet.interfaces.IProducer

View In Hierarchy

A process that integrates with the Twisted event loop.

If your subprocess is a python program, you need to:

  • Run python.exe with the '-u' command line option - this turns on unbuffered I/O. Buffering stdout/err/in can cause problems, see e.g. http://support.microsoft.com/default.aspx?scid=kb;EN-US;q1903

  • If you don't want Windows messing with data passed over stdin/out/err, set the pipes to be in binary mode:

     import os, sys, mscvrt
     msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY)
     msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
     msvcrt.setmode(sys.stderr.fileno(), os.O_BINARY)
    
Method __init__ Create a new child process.
Method __repr__ Return a string representation of the process.
Method close​Child​FD Close a file descriptor which is connected to the child process, identified by its FD in the child process.
Method close​Stderr Close stderr.
Method close​Stdin Close the process' stdin.
Method close​Stdout Close stdout.
Method connection​Lost​Notify Will be called 3 times, by stdout/err threads and process handle.
Method err​Connection​Lost Undocumented
Method get​Host Similar to getPeer, but returns an address describing this side of the connection.
Method get​Peer Get the remote address of this connection.
Method in​Connection​Lost Undocumented
Method lose​Connection Close the process' stdout, in and err.
Method maybe​Call​Process​Ended Call processEnded on protocol after final cleanup.
Method out​Connection​Lost Undocumented
Method pause​Producing Undocumented
Method register​Producer Register to receive data from a producer.
Method resume​Producing Undocumented
Method signal​Process Send a signal to the process.
Method stop​Producing Stop producing data.
Method unregister​Producer Stop consuming data from a producer, without disconnecting.
Method write Write data to the process' stdin.
Method write​Sequence Write data to the process' stdin.
Method write​To​Child Similar to ITransport.write but also allows the file descriptor in the child process which will receive the bytes to be specified.
Class Variable closed​Notifies Undocumented
Instance Variable h​Process Undocumented
Instance Variable h​Stderr​R Undocumented
Instance Variable h​Stdin​W Undocumented
Instance Variable h​Stdout​R Undocumented
Instance Variable h​Thread Undocumented
Instance Variable stderr Undocumented
Instance Variable stdin Undocumented
Instance Variable stdout Undocumented
Method _get​Reason Undocumented

Inherited from _PollingTimer:

Instance Variable reactor Undocumented
Method _add​Pollable​Resource Undocumented
Method _check​Polling​State Undocumented
Method _pause Undocumented
Method _poll​Event Undocumented
Method _reschedule Undocumented
Method _start​Polling Undocumented
Method _stop​Polling Undocumented
Method _unpause Undocumented
Instance Variable _current​Timeout Undocumented
Instance Variable _paused Undocumented
Instance Variable _poll​Timer Undocumented
Instance Variable _resources Undocumented

Inherited from BaseProcess:

Method process​Ended This is called when the child terminates.
Class Variable lost​Process Undocumented
Instance Variable pid Undocumented
Instance Variable proto Undocumented
Instance Variable status Undocumented
Method _call​Process​Exited Undocumented
def __init__(self, reactor, protocol, command, args, environment, path): (source)
Create a new child process.
def __repr__(self): (source)
Return a string representation of the process.
Returns
strUndocumented
def closeChildFD(self, fd): (source)
Close a file descriptor which is connected to the child process, identified by its FD in the child process.
def closeStderr(self): (source)
def closeStdin(self): (source)
Close the process' stdin.
def closeStdout(self): (source)
def connectionLostNotify(self): (source)
Will be called 3 times, by stdout/err threads and process handle.
def errConnectionLost(self): (source)

Undocumented

def getHost(self): (source)
Similar to getPeer, but returns an address describing this side of the connection.
Returns
An IAddress provider.
def getPeer(self): (source)

Get the remote address of this connection.

Treat this method with caution. It is the unfortunate result of the CGI and Jabber standards, but should not be considered reliable for the usual host of reasons; port forwarding, proxying, firewalls, IP masquerading, etc.

Returns
An IAddress provider.
def inConnectionLost(self): (source)

Undocumented

def loseConnection(self): (source)
Close the process' stdout, in and err.
def maybeCallProcessEnded(self): (source)
Call processEnded on protocol after final cleanup.
def outConnectionLost(self): (source)

Undocumented

def pauseProducing(self): (source)

Undocumented

def registerProducer(self, producer, streaming): (source)

Register to receive data from a producer.

This sets self to be a consumer for a producer. When this object runs out of data (as when a send(2) call on a socket succeeds in moving the last data from a userspace buffer into a kernelspace buffer), it will ask the producer to resumeProducing().

For IPullProducer providers, resumeProducing will be called once each time data is required.

For IPushProducer providers, pauseProducing will be called whenever the write buffer fills up and resumeProducing will only be called when it empties. The consumer will only call resumeProducing to balance a previous pauseProducing call; the producer is assumed to start in an un-paused state.

Parameters
producerUndocumented
streamingTrue if producer provides IPushProducer, False if producer provides IPullProducer.
Raises
RuntimeErrorIf a producer is already registered.
def resumeProducing(self): (source)

Undocumented

def signalProcess(self, signalID): (source)
Send a signal to the process.
Parameters
signal​ID

can be

  • one of "KILL", "TERM", or "INT". These will be implemented in a cross-platform manner, and so should be used if possible.
  • an integer, where it represents a POSIX signal ID.
Raises
twisted.internet.error.ProcessExitedAlreadyIf the process has already exited.
OSErrorIf the os.kill call fails with an errno different from ESRCH.
def stopProducing(self): (source)

Stop producing data.

This tells a producer that its consumer has died, so it must stop producing data for good.

def unregisterProducer(self): (source)
Stop consuming data from a producer, without disconnecting.
def write(self, data): (source)
Write data to the process' stdin.
Parameters
data:bytesUndocumented
def writeSequence(self, seq): (source)
Write data to the process' stdin.
Parameters
seq:list of bytesUndocumented
def writeToChild(self, fd, data): (source)

Similar to ITransport.write but also allows the file descriptor in the child process which will receive the bytes to be specified.

This implementation is limited to writing to the child's standard input.

Parameters
fd:intThe file descriptor to which to write. Only stdin (0) is supported.
data:bytesThe bytes to write.
Returns
None
Raises
KeyErrorIf fd is anything other than the stdin file descriptor (0).
closedNotifies: int = (source)

Undocumented

hProcess = (source)

Undocumented

hStderrR = (source)

Undocumented

hStdinW = (source)

Undocumented

hStdoutR = (source)

Undocumented

hThread = (source)

Undocumented

stderr = (source)

Undocumented

stdin = (source)

Undocumented

stdout = (source)

Undocumented

def _getReason(self, status): (source)

Undocumented