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.

Parameters:
command -

name of the child process executable


           (type=

str

)
args -

child process arguments (argv)


           (type=

sequence of str

)
expected -

valid exit status values


           (type=

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.

Parameters:
stdout -

use as standard output of child process, defaults to internal pipe or /dev/null.


           (type=

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.

)
stdin -

use as standard input of child process, defaults to /dev/null.


           (type=

file-like object with a fileno method or raw file descriptor (int).

)
stderr -

use as standard error of child process. Defaults to a pipe for error reporting (see ExecProblem) and logging.


           (type=

file-like object with a fileno method or raw file descriptor (int).

)
closefds -

file descriptors to close in the child process.


           (type=

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.

Raises:
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.

Returns:

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


Generated by Epydoc 2.1 on Fri Jul 7 17:05:35 2006 http://epydoc.sf.net