Go to the latest version of this document.
search in docstrings

Search bar offers the following options:

- Term presence. The below example searches for documents that must contain “foo”, might contain “bar” and must not contain “baz”: `+foo bar -baz`
- Wildcards. The below example searches for documents with words beginning with “foo”: `foo*`
- Search in specific fields. The following search matches all objects in "twisted.mail" that matches “search”: `+qname:twisted.mail.* +search`

  Possible fields: 'name', 'qname' (fully qualified name), 'docstring', and 'kind'. Last two fields are only applicable if "search in docstrings" is enabled.

- Fuzzy matches. The following search matches all documents that have a word within 1 edit distance of “foo”: `foo~1`

Results provided by Lunr.js

# ``twisted`.`internet`.`process`.`Process``

class documentation

`class Process(_BaseProcess): (source)`

Implements interfaces: `twisted.internet.interfaces.IProcessTransport`

View In Hierarchy

An operating-system Process.

This represents an operating-system process with arbitrary input/output pipes connected to it. Those pipes may represent standard input, standard output, and standard error, or any other file descriptor.

On UNIX, this is implemented using fork(), exec(), pipe() and fcntl(). These calls may not exist elsewhere so this code is not cross-platform. (also, windows can only select on sockets...)

Method | `__init__` | Spawn an operating-system process.
Method | `childConnectionLost` | Undocumented
Method | `childDataReceived` | Undocumented
Method | `closeChildFD` | Close a file descriptor which is connected to the child process, identified by its FD in the child process.
Method | `closeStderr` | Close stderr.
Method | `closeStdin` | Call this to close standard input on this process.
Method | `closeStdout` | Close stdout.
Method | `getHost` | Similar to getPeer, but returns an address describing this side of the connection.
Method | `getPeer` | Get the remote address of this connection.
Method | `loseConnection` | Close stdin, stderr and stdout.
Method | `maybeCallProcessEnded` | Call processEnded on protocol after final cleanup.
Method | `pauseProducing` | Undocumented
Method | `registerProducer` | Call this to register producer for standard input.
Method | `resumeProducing` | Undocumented
Method | `unregisterProducer` | Call this to unregister producer for standard input.
Method | `write` | Call this to write to standard input on this process.
Method | `writeSequence` | Call this to write to standard input on this process.
Method | `writeToChild` | Similar to `ITransport.write` but also allows the file descriptor in the child process which will receive the bytes to be specified.
Class Variable | `debug` | Undocumented
Class Variable | `debug_child` | Undocumented
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.
Class Variable | `status` | Undocumented
Instance Variable | `pipes` | Undocumented
Instance Variable | `proto` | Undocumented
Method | `_setupChild` | fdmap[childFD] = parentFD

Inherited from `_BaseProcess`:

Method | `__repr__` | String representation of a process.
Method | `reapProcess` | Try to reap a process (without blocking) via waitpid.
Method | `signalProcess` | Send the given signal `signalID` to the process. It'll translate a few signals ('HUP', 'STOP', 'INT', 'KILL', 'TERM') from a string representation to its int value, otherwise it'll pass directly the value provided...
Method | `_execChild` | The exec() which is done in the forked child.
Method | `_fork` | Fork and then exec sub-process.
Method | `_getReason` | Undocumented
Method | `_resetSignalDisposition` | Undocumented

Inherited from `BaseProcess` (via `_BaseProcess`):

Method | `processEnded` | This is called when the child terminates.
Class Variable | `lostProcess` | Undocumented
Method | `_callProcessExited` | Undocumented

def __init__(self, reactor, executable, args, environment, path, proto, uid=None, gid=None, childFDs=None): (source)
overrides `twisted.internet._baseprocess.BaseProcess.__init__`

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 childConnectionLost(self, childFD, reason): (source)

Undocumented

def childDataReceived(self, name, data): (source)

Undocumented

def closeChildFD(self, childFD): (source)
from `twisted.internet.interfaces.IProcessTransport`

Close a file descriptor which is connected to the child process, identified by its FD in the child process.

def closeStderr(self): (source)
from `twisted.internet.interfaces.IProcessTransport`

Close stderr.

def closeStdin(self): (source)
from `twisted.internet.interfaces.IProcessTransport`

Call this to close standard input on this process.

def closeStdout(self): (source)
from `twisted.internet.interfaces.IProcessTransport`

Close stdout.

def getHost(self): (source)
from `twisted.internet.interfaces.ITransport`

Similar to getPeer, but returns an address describing this side of the connection.

Returns
An `IAddress` provider.

def getPeer(self): (source)
from `twisted.internet.interfaces.ITransport`

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 loseConnection(self): (source)
from `twisted.internet.interfaces.IProcessTransport`

Close stdin, stderr and stdout.

def maybeCallProcessEnded(self): (source)
overrides `twisted.internet._baseprocess.BaseProcess.maybeCallProcessEnded`

Call processEnded on protocol after final cleanup.

def pauseProducing(self): (source)

Undocumented

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

Call this to register producer for standard input.

If there is no standard input producer.stopProducing() will be called immediately.

def resumeProducing(self): (source)

Undocumented

def unregisterProducer(self): (source)

Call this to unregister producer for standard input.

def write(self, data): (source)
from `twisted.internet.interfaces.ITransport`

Call this to write to standard input on this process.

NOTE: This will silently lose data if there is no standard input.

def writeSequence(self, seq): (source)
from `twisted.internet.interfaces.ITransport`

Call this to write to standard input on this process.

NOTE: This will silently lose data if there is no standard input.

def writeToChild(self, childFD, data): (source)
from `twisted.internet.interfaces.IProcessTransport`

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

Parameters
childFD | The file descriptor to which to write.
data | The bytes to write.
Raises
`KeyError` | If `childFD` is not a file descriptor that was mapped in the child when `IReactorProcess.spawnProcess` was used to create it.

debug: `bool` = (source)

Undocumented

debug_child: `bool` = (source)

Undocumented

pid = (source)
from `twisted.internet.interfaces.IProcessTransport`
overrides `twisted.internet.process._BaseProcess.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.

status: `int` = (source)
overrides `twisted.internet.process._BaseProcess.status`

Undocumented

pipes: `dict` = (source)

Undocumented

proto = (source)
overrides `twisted.internet._baseprocess.BaseProcess.proto`

Undocumented

def _setupChild(self, fdmap): (source)
overrides `twisted.internet.process._BaseProcess._setupChild`

fdmap[childFD] = parentFD

The child wants to end up with 'childFD' attached to what used to be the parent's parentFD. As an example, a bash command run like 'command 2>&1' would correspond to an fdmap of {0:0, 1:1, 2:1}. 'command >foo.txt' would be {0:0, 1:os.open('foo.txt'), 2:2}.

This is accomplished in two steps:

        1. close all file descriptors that aren't values of fdmap.  This
           means 0 .. maxfds (or just the open fds within that range, if
           the platform supports '/proc/<pid>/fd').

        2. for each childFD::

             - if fdmap[childFD] == childFD, the descriptor is already in
               place.  Make sure the CLOEXEC flag is not set, then delete
               the entry from fdmap.

             - if childFD is in fdmap.values(), then the target descriptor
               is busy. Use os.dup() to move it elsewhere, update all
               fdmap[childFD] items that point to it, then close the
               original. Then fall through to the next case.

             - now fdmap[childFD] is not in fdmap.values(), and is free.
               Use os.dup2() to move it to the right place, then close the
               original.