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

Class ChildProcess


Description of a child process, for error handling.

Method Summary
  __init__(self, command, args, expected, chdir, logger)
Create a child process descriptor.
  spawn(self, stdout, stdin, stderr, closefds)
Fork, setup file descriptors, and exec child process.
  wait(self)
Wait for process and check its termination status.
  wait_nocheck(self)
Wait for process and return exit result.

Method Details

__init__(self, command, args, expected=0, chdir=None, logger=None)
(Constructor)

Create a child process descriptor.

The child process must have already been created. The
`command`, `args` and `expected` parameters are used for error
reporting.

:param command: name of the child process executable
:type command: str
:param args: child process arguments (argv)
:type args: sequence of str
:param expected: valid exit status values
:type expected: int or sequence of int

spawn(self, stdout=None, stdin=None, stderr=None, closefds=[])

Fork, setup file descriptors, and exec child process.

The `stdout`, `stdin` and `stderr` file-like objects can be
raw file descriptors (ints) or file-like objects with a
``fileno`` method returning a file descriptor.

When building a pipe, one side of a pipe is used as `stdout`,
`stdin` or `stderr`, and the other is included in the
`closefds` list, so the child process will be able to detect a
broken pipe.

:param stdin: use as standard input of child process, defaults
    to ``/dev/null``.
:type stdin: file-like object with a ``fileno`` method or raw
    file descriptor (``int``).
:param stdout: use as standard output of child process,
    defaults to internal pipe or ``/dev/null``.
:type stdout: file-like object with a ``fileno`` method or raw
    file descriptor (``int``). If a logger was specified,
    defaults to a pipe for logging, if no logger was
    specified, defaults to ``/dev/null``.
:param stderr: use as standard error of child process.
    Defaults to a pipe for error reporting (see `ExecProblem`)
    and logging.
:type stderr: file-like object with a ``fileno`` method or raw
    file descriptor (``int``).
:param closefds: file descriptors to close in the child process.
:type closefds: iterable of int

wait(self)

Wait for process and check its termination status.

If the process exited, set ``self.status`` to its exit status.

if the process was terminated by a signal, set ``self.signal``
to the value of this signal.

:raise ExecProblem: process was killed by a signal or exit
    status is not is ``self.expected``

wait_nocheck(self)

Wait for process and return exit result.

This (internally used) variant of `wait` is useful when you
want to wait for a child process, but not raise an exception
if it was terminated abnormally. Typically, that's what you
want if you killed the child process.

:return: second element of the tuple returned by os.wait()

Generated by Epydoc 2.1 on Tue Jul 18 16:30:57 2006 http://epydoc.sf.net