class documentation

class PTYProcess(abstract.FileDescriptor, _BaseProcess): (source)

Implements interfaces: twisted.internet.interfaces.IProcessTransport

View In Hierarchy

An operating-system Process that uses PTY support.
Method __init__ Spawn an operating-system 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 stdin after all data has been written out.
Method close​Stdout Close stdout.
Method connection​Lost I call this to clean up when one or all of my connections has died.
Method do​Read Called when my standard output stream is ready for reading.
Method fileno This returns the file number of standard output on this process.
Method maybe​Call​Process​Ended Call processEnded on protocol after final cleanup.
Method write​Some​Data Write some data to the open process.
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 pid From before IProcessProtocol.makeConnection is called to before IProcessProtocol.processEnded is called, pid is an int giving the platform process ID of this process. pid is None at all other times.
Instance Variable connected Undocumented
Instance Variable fd Undocumented
Instance Variable status Undocumented
Method _setup​Child Set up child process after fork() but before exec().

Inherited from FileDescriptor:

Method do​Write Called when data can be written.
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 lose​Connection Close the connection at the next available opportunity.
Method lose​Write​Connection Undocumented
Method pause​Producing Pause producing data.
Method read​Connection​Lost Indicates read connection was lost.
Method resume​Producing Resume producing data.
Method start​Reading Start waiting for read availability.
Method start​Writing Start waiting for write availability.
Method stop​Consuming Stop consuming data.
Method stop​Producing Stop producing data.
Method stop​Reading Stop waiting for read availability.
Method stop​Writing Stop waiting for write availability.
Method write Reliably write some data.
Method write​Connection​Lost Indicates write connection was lost.
Method write​Sequence Reliably write a sequence of data.
Constant SEND​_LIMIT Undocumented
Class Variable buffer​Size Undocumented
Class Variable disconnecting Undocumented
Instance Variable data​Buffer Undocumented
Instance Variable disconnected Undocumented
Instance Variable offset Undocumented
Instance Variable producer Undocumented
Instance Variable producer​Paused Undocumented
Instance Variable reactor Undocumented
Method _close​Write​Connection Undocumented
Method _is​Send​Buffer​Full Determine whether the user-space send buffer for this transport is full or not.
Method _maybe​Pause​Producer Possibly pause a producer, if there is one and the send buffer is full.
Method _post​Lose​Connection Called after a loseConnection(), when all data has been written.
Class Variable _write​Disconnected Undocumented
Instance Variable _temp​Data​Buffer Undocumented
Instance Variable _temp​Data​Len Undocumented
Instance Variable _write​Disconnecting Undocumented

Inherited from _ConsumerMixin (via FileDescriptor):

Method register​Producer Register to receive data from a producer.
Method unregister​Producer Stop consuming data from a producer, without disconnecting.
Instance Variable streaming​Producer bool or int

Inherited from _LogOwner (via FileDescriptor):

Method log​Prefix Override this method to insert custom logging behavior. Its return value will be inserted in front of every line. It may be called more times than the number of output lines.
Method _get​Log​Prefix Determine the log prefix to use for messages related to applicationObject, which may or may not be an interfaces.ILoggingContext provider.

Inherited from _BaseProcess:

Method __repr__ String representation of a process.
Method reap​Process Try to reap a process (without blocking) via waitpid.
Method signal​Process No summary
Method _exec​Child The exec() which is done in the forked child.
Method _fork Fork and then exec sub-process.
Method _get​Reason Undocumented
Method _reset​Signal​Disposition Undocumented

Inherited from BaseProcess (via _BaseProcess):

Method process​Ended This is called when the child terminates.
Class Variable lost​Process Undocumented
Instance Variable proto Undocumented
Method _call​Process​Exited Undocumented
def __init__(self, reactor, executable, args, environment, path, proto, uid=None, gid=None, usePTY=None): (source)

Spawn an operating-system process.

This is where the hard work of disconnecting all currently open files / forking / executing the new process happens. (This is executed automatically when a Process is instantiated.)

This will also run the subprocess as a given user ID and group ID, if specified. (Implementation Note: this doesn't support all the arcane nuances of setXXuid on UNIX: it will assume that either your effective or real UID is 0.)

def closeChildFD(self, descriptor): (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 stdin after all data has been written out.
def closeStdout(self): (source)
def connectionLost(self, reason): (source)
I call this to clean up when one or all of my connections has died.
def doRead(self): (source)
Called when my standard output stream is ready for reading.
def fileno(self): (source)
This returns the file number of standard output on this process.
def maybeCallProcessEnded(self): (source)
Call processEnded on protocol after final cleanup.
def writeSomeData(self, data): (source)
Write some data to the open process.
def writeToChild(self, childFD, data): (source)
Similar to ITransport.write but also allows the file descriptor in the child process which will receive the bytes to be specified.
Parameters
child​FDThe file descriptor to which to write.
dataThe bytes to write.
Raises
KeyErrorIf childFD is not a file descriptor that was mapped in the child when IReactorProcess.spawnProcess was used to create it.
From before IProcessProtocol.makeConnection is called to before IProcessProtocol.processEnded is called, pid is an int giving the platform process ID of this process. pid is None at all other times.

Undocumented

def _setupChild(self, masterfd, slavefd): (source)

Set up child process after fork() but before exec().

This involves:

  • closing masterfd, since it is not used in the subprocess
  • creating a new session with os.setsid
  • changing the controlling terminal of the process (and the new session) to point at slavefd
  • duplicating slavefd to standard input, output, and error
  • closing all other open file descriptors (according to _listOpenFDs)
  • re-setting all signal handlers to SIG_DFL
Parameters
masterfd:intThe master end of a PTY file descriptors opened with openpty.
slavefd:intThe slave end of a PTY opened with openpty.