twisted.internet.process.Process(_BaseProcess)
class documentationtwisted.internet.process
View Source
(View In Hierarchy)
Implements interfaces: twisted.internet.interfaces.IProcessTransport
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 | writeToChild | Similar to ITransport.write
but also allows the file descriptor in the child process which will receive
the bytes to be specified. |
Method | closeChildFD | Close a file descriptor which is connected to the child process, identified by its FD in the child process. |
Method | pauseProducing | Undocumented |
Method | resumeProducing | Undocumented |
Method | closeStdin | Call this to close standard input on this process. |
Method | closeStdout | Close stdout. |
Method | closeStderr | Close stderr. |
Method | loseConnection | Close stdin, stderr and stdout. |
Method | write | Call this to write to standard input on this process. |
Method | registerProducer | Call this to register producer for standard input. |
Method | unregisterProducer | Call this to unregister producer for standard input. |
Method | writeSequence | Call this to write to standard input on this process. |
Method | childDataReceived | Undocumented |
Method | childConnectionLost | Undocumented |
Method | maybeCallProcessEnded | Call processEnded on protocol after final cleanup. |
Method | _setupChild | fdmap[childFD] = parentFD |
Inherited from BaseProcess (via _BaseProcess):
Method | processEnded | This is called when the child terminates. |
Method | _callProcessExited | Undocumented |
Inherited from BaseProcess (via _BaseProcess):
Method | processEnded | This is called when the child terminates. |
Method | _callProcessExited | Undocumented |
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.)
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.
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. (type: int ) |
data | The bytes to write. (type: bytes ) | |
Returns | None | |
Raises | KeyError | If childFD is not a file descriptor that was mapped in the
child when IReactorProcess.spawnProcess
was used to create it. |
Close a file descriptor which is connected to the child process, identified by its FD in the child process.
Call this to write to standard input on this process.
NOTE: This will silently lose data if there is no standard input.
Call this to register producer for standard input.
If there is no standard input producer.stopProducing() will be called immediately.
Call this to write to standard input on this process.
NOTE: This will silently lose data if there is no standard input.