Package twisted :: Package internet :: Module process :: Class Process
[frames | no frames]

Class Process

     Ephemeral --+
                 |
 Ephemeral --+   |
             |   |
    Logger --+   |
             |   |
FileDescriptor --+
                 |
                Process


An operating-system Process.

This represents an operating-system process with standard input, standard output, and standard error streams connected to it.

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 Summary
  __init__(self, reactor, command, args, environment, path, proto, uid, gid)
Spawn an operating-system process.
  closeStderr(self)
Close stderr.
  closeStdin(self)
Call this to close standard input on this process.
  closeStdout(self)
Close stdout.
  connectionLost(self, reason)
stdout closed.
  doError(self)
Called when my standard error stream is ready for reading.
  doRead(self)
Called when my standard output stream is ready for reading.
  doWrite(self)
Called when my standard output stream is ready for writing.
  errConnectionLost(self)
  fileno(self)
This returns the file number of standard output on this process.
  inConnectionLost(self)
  loseConnection(self)
Close the connection at the next available opportunity.
  maybeCallProcessEnded(self)
  processEnded(self, status)
  reapProcess(self)
Try to reap a process (without blocking) via waitpid.
  signalProcess(self, signalID)
  write(self, data)
Call this to write to standard input on this process.
    Inherited from FileDescriptor
  _postLoseConnection(self)
Called after a loseConnection(), when all data has been written.
  pauseProducing(self)
  registerProducer(self, producer, streaming)
Register to receive data from a producer.
  resumeProducing(self)
  startReading(self)
Start waiting for read availability.
  startWriting(self)
Start waiting for write availability.
  stopConsuming(self)
Stop consuming data.
  stopProducing(self)
  stopReading(self)
Stop waiting for read availability.
  stopWriting(self)
Stop waiting for write availability.
  unregisterProducer(self)
Stop consuming data from a producer, without disconnecting.
  writeSequence(self, iovec)
  writeSomeData(self, data)
Write as much as possible of the given data, immediately.
    Inherited from Logger
  logPrefix(self)
Override this method to insert custom logging behavior.
    Inherited from Ephemeral
  __getstate__(self)
  __setstate__(self, state)

Class Variable Summary
int lostErrorConnection = 0                                                                     
int lostInConnection = 0                                                                     
int lostOutConnection = 0                                                                     
int lostProcess = 0                                                                     
    Inherited from FileDescriptor
tuple __implements__ = (<class twisted.internet.interfaces.IPr...
int bufferSize = 65536                                                                 
int connected = 0                                                                     
str dataBuffer = ''
int disconnected = 0                                                                     
int disconnecting = 0                                                                     
int offset = 0                                                                     
NoneType producer = None                                                                  
int producerPaused = 0                                                                     
int streamingProducer = 0                                                                     

Method Details

__init__(self, reactor, command, args, environment, path, proto, uid=None, gid=None)
(Constructor)

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.)
Overrides:
twisted.internet.abstract.FileDescriptor.__init__

closeStderr(self)

Close stderr.

closeStdin(self)

Call this to close standard input on this process.

closeStdout(self)

Close stdout.

connectionLost(self, reason)

stdout closed.
Overrides:
twisted.internet.abstract.FileDescriptor.connectionLost

doError(self)

Called when my standard error stream is ready for reading.

doRead(self)

Called when my standard output stream is ready for reading.

doWrite(self)

Called when my standard output stream is ready for writing.

This will only happen in the case where the pipe to write to is broken.
Overrides:
twisted.internet.abstract.FileDescriptor.doWrite

fileno(self)

This returns the file number of standard output on this process.
Overrides:
twisted.internet.abstract.FileDescriptor.fileno

loseConnection(self)

Close the connection at the next available opportunity.

Call this to cause this FileDescriptor to lose its connection; if this is in the main loop, it will lose its connection as soon as it's done flushing its write buffer; otherwise, it will wake up the main thread and lose the connection immediately.

If you have a producer registered, the connection won't be closed until the producer is finished. Therefore, make sure you unregister your producer when it's finished, or the connection will never close.
Overrides:
twisted.internet.abstract.FileDescriptor.loseConnection (inherited documentation)

reapProcess(self)

Try to reap a process (without blocking) via waitpid.

This is called when sigchild is caught or a Process object loses its "connection" (stdout is closed) This ought to result in reaping all zombie processes, since it will be called twice as often as it needs to be.

(Unfortunately, this is a slightly experimental approach, since UNIX has no way to be really sure that your process is going to go away w/o blocking. I don't want to block.)

write(self, data)

Call this to write to standard input on this process.
Overrides:
twisted.internet.abstract.FileDescriptor.write

Class Variable Details

lostErrorConnection

Type:
int
Value:
0                                                                     

lostInConnection

Type:
int
Value:
0                                                                     

lostOutConnection

Type:
int
Value:
0                                                                     

lostProcess

Type:
int
Value:
0                                                                     

Generated by Epydoc 2.0 on Sat Oct 25 00:54:44 2003 http://epydoc.sf.net