Package pybaz :: Package backends :: Module forkexec :: Class exec_safe_iter_stdout
[frames] | no frames]

Class exec_safe_iter_stdout

source code

object --+
         |
        exec_safe_iter_stdout

Iterator over the output of a child process.

Fork/exec a process with its output piped. Each iteration will
cause a iteration of the process output pipe. The pipe is properly
closed whenever the output is exhausted or the iterator is
deleted.

If the output is exhausted, the process exit status is checked and
an ExecError exception will be raised for abnormal or unexpected
exit status.



Instance Methods
 
__init__(self, program, args=[], stdin=None, stderr=None, expected=0, delsignal=None, chdir=None, logger=None)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
 
__del__(self)
Destructor.
 
close(self)
Close the pipe and wait the child process.
 
__iter__(self)
Iterator.
 
next(self)
Iteration method.

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Properties
  finished
Whether the underlying process has terminated.
  status
Exit status of the underlying process.

Inherited from object: __class__

Method Details

__init__(self, program, args=[], stdin=None, stderr=None, expected=0, delsignal=None, chdir=None, logger=None)
(Constructor)

 
x.__init__(...) initializes x; see x.__class__.__doc__ for signature

Overrides: object.__init__
(inherited documentation)

__del__(self)
(Destructor)

 
Destructor. If needed, close the pipe and wait the child process.

If child process has already been joined, it means the iterator was
deleted before being exhausted. It is assumed the return status is not
cared about.

close(self)

 
Close the pipe and wait the child process.

If the output is not exhausted yet, you should be prepared to
handle the error condition caused by breaking the pipe.

__iter__(self)

 
Iterator. Return self.

next(self)

 
Iteration method. Iterate on the pipe file.

Close the pipe and wait the child process once output is exhausted.

Use `file.readline` instead of `file.next` because we want
maximal responsiveness to incremental output. The pipe
mechanism itself provides buffering.


Property Details

finished

Whether the underlying process has terminated.

Get Method:
pybaz.backends.forkexec.exec_safe_iter_stdout._get_finished(self) - Whether the underlying process has terminated.

status

Exit status of the underlying process.

Raises ValueError if the process has not yet finished. (Hm...
should be AttributeError). Can be None if the process was
killed by a signal.

Get Method:
pybaz.backends.forkexec.exec_safe_iter_stdout._get_status(self) - Exit status of the underlying process.