scenario.subprocess module¶
SubProcess class definition.
- class SubProcess¶
Bases:
objectSub-process execution.
- __init__(*args)¶
- Parameters:
args – Command line arguments. May be the first arguments only, then rely on the
addargs()method to add others.
- _logger¶
See
setlogger().
- _stdout_line_handler¶
Handler to call on each stdout line.
- _stderr_line_handler¶
Handler to call on each stderr line.
- _exit_on_error_code¶
See
exitonerror().
- returncode¶
Sub-process return code.
- stdout¶
Standard output as a string.
- stderr¶
Standard error as a string.
- time¶
Time statistics.
- _popen¶
subprocess.Popeninstance.
- _stdout_reader¶
Stdout reader thread routine.
- _stderr_reader¶
Stderr reader thread routine.
- __repr__()¶
Canonical string representation.
- __str__()¶
Human readable string representation.
- tostring()¶
Human readable full string representation.
- addargs(*args)¶
Extra arguments addition.
- Parameters:
args – Extra arguments.
- Returns:
self
- hasargs(*args)¶
Determines whether the command line contains the given sequence of consecutive arguments.
- Parameters:
args – Sequence of arguments being searched.
- Returns:
Truewhen the arguments have been found,Falseotherwise.
- setenv(**kwargs)¶
Sets extra environment variables.
- Parameters:
kwargs – Extra environment variables.
- Returns:
self
- setcwd(cwd)¶
Sets the current working directory.
- Parameters:
cwd – Current working directory.
- Returns:
self
- setlogger(logger)¶
Directs log lines to the given logger instance.
- Parameters:
logger – Logger instance to use.
- Returns:
`` self``
- onstdoutline(handler)¶
Installs a handler to be called on each stdout line.
- Parameters:
handler – Handler to call on each stdout line.
- Returns:
self
- onstderrline(handler)¶
Installs a handler to be called on each stderr line.
- Parameters:
handler – Handler to call on each stderr line.
- Returns:
self
- exitonerror(exit_on_error_code)¶
Tells whether the main program should stop (
sys.exit()) in case of an error.- Parameters:
exit_on_error_code – Set to
Noneto keep executing in case of an error (default behaviour). Set to aErrorCodevalue to make the main program stop with the given error code.Trueis an equivalent forerrcodes.ErrorCode.INTERNAL_ERROR,Falseis an equivalent forNone.- Returns:
self
The return code is available through the
returncodeattribute.
- run(timeout=None)¶
Sub-process execution.
- Parameters:
timeout – Waiting timeout, in seconds.``None`` to wait infinitely.
- Returns:
self
The sub-process return code is available through the
returncodeattribute.
- runasync()¶
Launches the sub-process asynchronously.
Contrary to
run(), this method launches the sub-process, then returns without waiting for the end of it.
- _readstdoutthread()¶
Stdout reader thread routine.
- _readstderrthread()¶
Stderr reader thread routine.
- isrunning()¶
Tells whether the sub-process is currently running.
- Returns:
Truewhen the sub-process is still running.Falseotherwise.
- wait(timeout=None)¶
Waits for the sub-process to terminate.
- Parameters:
timeout – Waiting timeout, in seconds.
Noneto wait infinitely.- Returns:
self- Raises:
TimeoutError – When the sub-process did not terminate within
timeoutseconds.
- kill()¶
Kills the sub-process.
- Returns:
self
- _onerror(error_message, *args)¶
Error management.
Optionally logs the error and terminates the main process.
- Parameters:
error_message – Error message.
args – Error message arguments.
- _log(level, message, *args)¶
Pushes a log line to the attached logger, if any.
- Parameters:
level – Log level.
message – Log message.
args – Format arguments.