interface documentation

class twisted.internet.interfaces.IReactorProcess(Interface): (source)

Known implementations: twisted.internet.iocpreactor.reactor.IOCPReactor, twisted.internet.posixbase.PosixReactorBase

View In Hierarchy

Undocumented

Method spawnProcess Spawn a process, with a process protocol.
def spawnProcess(processProtocol, executable, args, env, path, uid, gid, usePTY, childFDs): (source)

Spawn a process, with a process protocol.

Arguments given to this function that are listed as bytes or unicode may be encoded or decoded depending on the platform and the argument type given. On UNIX systems (Linux, FreeBSD, macOS) and Python 2 on Windows, unicode arguments will be encoded down to bytes using the encoding given by sys.getfilesystemencoding, to be used with the "narrow" OS APIs. On Python 3 on Windows, bytes arguments will be decoded up to unicode using the encoding given by sys.getfilesystemencoding (mbcs before Python 3.6, utf8 thereafter) and given to Windows's native "wide" APIs.

ParametersprocessProtocolAn object which will be notified of all events related to the created process. (type: IProcessProtocol)
executablethe file name to spawn - the full path should be used. (type: Union[bytes, str])
argsthe command line arguments to pass to the process; a sequence of strings. The first string should be the executable's name. (type: Sequence[Union[bytes, str]])
envthe environment variables to pass to the child process. The resulting behavior varies between platforms. If:
  • env is not set:
    • On POSIX: pass an empty environment.
    • On Windows: pass os.environ.
  • env is None:
  • env is a dict:
    • On POSIX: pass the key/value pairs in env as the complete environment.
    • On Windows: update os.environ with the key/value pairs in the dict before passing it. As a consequence of bug #1640, passing keys with empty values in an effort to unset environment variables won't unset them.
(type: Optional[Mapping[AnyStr, AnyStr]])
paththe path to run the subprocess in - defaults to the current directory. (type: Union[bytes, str])
uiduser ID to run the subprocess as. (Only available on POSIX systems.) (type: int)
gidgroup ID to run the subprocess as. (Only available on POSIX systems.) (type: int)
usePTYif true, run this process in a pseudo-terminal. optionally a tuple of (masterfd, slavefd, ttyname), in which case use those file descriptors. (Not available on all systems.) (type: bool)
childFDsA dictionary mapping file descriptors in the new child process to an integer or to the string 'r' or 'w'.

If the value is an integer, it specifies a file descriptor in the parent process which will be mapped to a file descriptor (specified by the key) in the child process. This is useful for things like inetd and shell-like file redirection.

If it is the string 'r', a pipe will be created and attached to the child at that file descriptor: the child will be able to write to that file descriptor and the parent will receive read notification via the IProcessProtocol.childDataReceived callback. This is useful for the child's stdout and stderr.

If it is the string 'w', similar setup to the previous case will occur, with the pipe being readable by the child instead of writeable. The parent process can write to that file descriptor using IProcessTransport.writeToChild. This is useful for the child's stdin.

If childFDs is not passed, the default behaviour is to use a mapping that opens the usual stdin/stdout/stderr pipes.

(type: Mapping[int, Union[int, str]])
ReturnsAn object which provides IProcessTransport. (type: IProcessTransport)
RaisesOSErrorRaised with errno EAGAIN or ENOMEM if there are insufficient system resources to create a new process.
See Alsotwisted.internet.protocol.ProcessProtocol
API Documentation for Twisted, generated by pydoctor 20.12.1 at 2021-02-28 19:53:36.