| |
- spug.io.reactor.Reactable
-
- util.process.StreamWrapper
-
- util.process.InputStreamWrapper
- util.process.OutputStreamWrapper
- util.process.ChildProcess
-
- util.process.LineChildProcess
- util.process.ForkExecer
class ChildProcess |
|
Creates a child process and handles output to it and input from it. |
|
Methods defined here:
- __init__(self, cmd, start=False, processStarter=<class util.process.ForkExecer at 0x82c0e9c>, noPipes=False, noStdIn=False, noStdOut=False, noStdErr=False)
- parms:
cmd::
[list<string>] a list of the command arguments. The first item
in the list is the fully qualified path to the program to
execute.
start::
[boolean] if true, start the process immediately. If false,
the process must be explicitly started using the @start()
method.
processStarter::
[callable<list<string>>] A function which accepts a list of
arguments (including an executable as the zeroth argument) and
returns a process object. The process object must have a
wait() method (which waits for process termination) and stdin,
stdout and stderr attributes, which are file objects
implementing fileno() and read().
noPipes::
[boolean] disables all pipes (stdin, stdout & stderr) to and
from the child. Equivalent to setting all of /noStdIn/,
/noStdOut/, and /noStdErr/ to True.
noStdIn::
[boolean] disables standard input to the child
noStdOut::
[boolean] disables collection of standard output from the
child. child standard output will go to the parent process
standard output. @gotOutput() will never be called.
noStdErr::
[boolean] disables collection of standard error from the
child. child standard error will go to the parent process
standard error. @gotError() will never be called.
- close(self)
- Close the standard input stream.
- getRawStderr(self)
- getRawStdin(self)
- getRawStdout(self)
- gotError(self, data)
- Derived classes should override this method to capture data received
from the child's standard error stream. Base class version just
writes to our standard error.
- gotOutput(self, data)
- Derived classes should override this method to capture data received
from the child's standard output stream. Base class version just
writes to our standard output.
- kill(self, signal=15)
- Sends a kill signal to the child process.
- run(self)
- Runs the process and handles all input and output until termination.
The process will be started if it has not already been.
Returns the process' exit code.
- start(self)
- Starts the child process. Will raise an AssertionError if the
process is already started.
- wait(self)
- Waits for process termination, returns the result code.
This should not be called if the run() method is used, it should
always be called if the run method is not used.
- write(self, data)
- Writes data to the child process (actually, this queues the data.
Write will be performed when the child is ready to read.
Data descriptors defined here:
- stderr
- The child process stderr stream. This is an
OutputStreamWrapper instance. Note that every time this
attribute is accessed, a new StreamWrapper is created.
- stdin
- The child process stdin stream. This is an
InputStreamWrapper instance. Note that every time this
attribute is accessed, a new StreamWrapper is created.
- stdout
- The child process stdout stream. This is a
OutputStreamWrapper instance. Note that every time this
attribute is accessed, a new StreamWrapper is created.
|
class ForkExecer |
|
Standard implementation of fork\/exec. Creates a new process on
construction with wrapped pipes for communication to stdin, stdout, and
stderr. |
|
Methods defined here:
- __init__(self, cmd, stdin=None, stdout=None, stderr=None)
- kill(self, signal=15)
- Kills the process with the given signal. You should still call
"wait" after calling this or you will accumulate zombies.
- wait(self)
- Wait for child process to terminate and returns its exit code.
|
class LineChildProcess(ChildProcess) |
|
Processor for child processes to allow you to handle complete lines of
output from stdout and stderr. gotOutput() and gotError() are
overriden to collect input into buffers and pass individual lines to
gotOutLine() and gotErrLine().
Note that this is only suitable for processes whose output and error
streams produce output as finite lines of text terminated by the newline
character. |
|
Methods defined here:
- __init__(self, cmd, **kwargs)
- gotErrLine(self, data)
- Derived classes should implement this to capture single lines of
output. Base class version does nothing.
- gotError(self, data)
- Overrides @ChildProcess.gotError() to split output into single line
chunks and feed them to @gotOutLine().
- gotOutLine(self, line)
- Derived classes should implement this to capture single lines of
output. Base class version does nothing.
- gotOutput(self, data)
- Overrides @ChildProcess.gotOutput() to split output into single line
chunks and feed them to @gotOutLine().
Methods inherited from ChildProcess:
- close(self)
- Close the standard input stream.
- getRawStderr(self)
- getRawStdin(self)
- getRawStdout(self)
- kill(self, signal=15)
- Sends a kill signal to the child process.
- run(self)
- Runs the process and handles all input and output until termination.
The process will be started if it has not already been.
Returns the process' exit code.
- start(self)
- Starts the child process. Will raise an AssertionError if the
process is already started.
- wait(self)
- Waits for process termination, returns the result code.
This should not be called if the run() method is used, it should
always be called if the run method is not used.
- write(self, data)
- Writes data to the child process (actually, this queues the data.
Write will be performed when the child is ready to read.
Data descriptors inherited from ChildProcess:
- stderr
- The child process stderr stream. This is an
OutputStreamWrapper instance. Note that every time this
attribute is accessed, a new StreamWrapper is created.
- stdin
- The child process stdin stream. This is an
InputStreamWrapper instance. Note that every time this
attribute is accessed, a new StreamWrapper is created.
- stdout
- The child process stdout stream. This is a
OutputStreamWrapper instance. Note that every time this
attribute is accessed, a new StreamWrapper is created.
|
|