shell_proc.py

shell_proc.py#

Some basic shell utilities, used for ExternalCodeComp mostly.

exception openmdao.utils.shell_proc.CalledProcessError(returncode, cmd, errormsg)[source]

Bases: CalledProcessError

subprocess.CalledProcessError plus errormsg attribute.

Parameters:
returncodeint

Error code for this error.

cmdstr or list

If a string, then this is the command line to execute, and the subprocess.Popen shell argument is set True. Otherwise, this is a list of arguments; the first is the command to execute.

errormsgstr

Error message for this error.

Attributes:
errormsgstr

Error message saved for string access.

__init__(returncode, cmd, errormsg)[source]

Initialize.

class openmdao.utils.shell_proc.ShellProc(args, stdin=None, stdout=None, stderr=None, env=None, universal_newlines=False)[source]

Bases: Popen

A slight modification to subprocess.Popen.

If args is a string, then the shell argument is set True. Updates a copy of os.environ with env and opens files for any stream which is a str.

Parameters:
argsstr or list

If a string, then this is the command line to execute and the subprocess.Popen shell argument is set True. Otherwise, this is a list of arguments; the first is the command to execute.

stdinstr, file, or int

Specify handling of stdin stream. If a string, a file of that name is opened. Otherwise, see the subprocess documentation.

stdoutstr, file, or int

Specify handling of stdout stream. If a string, a file of that name is opened. Otherwise, see the subprocess documentation.

stderrstr, file, or int

Specify handling of stderr stream. If a string, a file of that name is opened. Otherwise, see the subprocess documentation.

envdict

Environment variables for the command.

universal_newlinesbool

Set to True to turn on universal newlines.

Attributes:
_stdin_argstr, file, or int

Save handle to make closing easier.

_stdout_argstr, file, or int

Save handle to make closing easier.

_stderr_argstr, file, or int

Save handle to make closing easier.

_inpstr, file, or int

Save handle to make closing easier.

_outstr, file, or int

Save handle to make closing easier.

_errstr, file, or int

Save handle to make closing easier.

Methods

close_files()

Close files that were implicitly opened.

communicate([input, timeout])

Interact with process: Send data to stdin and close it.

error_message(return_code)

Return error message for return_code.

kill()

Kill the process with SIGKILL

poll()

Check if child process has terminated.

send_signal(sig)

Send a signal to the process.

terminate([timeout])

Stop child process.

wait([poll_delay, timeout])

Poll for command completion or timeout.

__init__(args, stdin=None, stdout=None, stderr=None, env=None, universal_newlines=False)[source]

Initialize.

close_files()[source]

Close files that were implicitly opened.

error_message(return_code)[source]

Return error message for return_code.

The error messages are derived from the operating system definitions. Some programs don’t necessarily return exit codes conforming to these definitions.

Parameters:
return_codeint

Return code from poll().

Returns:
str

Error Message string.

terminate(timeout=None)[source]

Stop child process.

If timeout is specified, then wait() will be called to wait for the process to terminate.

Parameters:
timeoutfloat (seconds)

Maximum time to wait for the process to stop. A value of zero implies an infinite maximum wait.

Returns:
int

Return Code.

str

Error Message.

wait(poll_delay=0.0, timeout=0.0)[source]

Poll for command completion or timeout.

Closes any files implicitly opened.

Parameters:
poll_delayfloat (seconds)

Time to delay between polling for command completion. A value of zero uses an internal default.

timeoutfloat (seconds)

Maximum time to wait for command completion. A value of zero implies an infinite maximum wait.

Returns:
int

Return Code.

str

Error Message.

openmdao.utils.shell_proc.call(args, stdin=None, stdout=None, stderr=None, env=None, poll_delay=0.0, timeout=0.0)[source]

Run command with arguments.

Parameters:
argsstr or list

If a string, then this is the command line to execute and the subprocess.Popen shell argument is set True. Otherwise, this is a list of arguments; the first is the command to execute.

stdinstr, file, or int

Specify handling of stdin stream. If a string, a file of that name is opened. Otherwise, see the subprocess documentation.

stdoutstr, file, or int

Specify handling of stdout stream. If a string, a file of that name is opened. Otherwise, see the subprocess documentation.

stderrstr, file, or int

Specify handling of stderr stream. If a string, a file of that name is opened. Otherwise, see the subprocess documentation.

envdict

Environment variables for the command.

poll_delayfloat (seconds)

Time to delay between polling for command completion. A value of zero uses an internal default.

timeoutfloat (seconds)

Maximum time to wait for command completion. A value of zero implies an infinite maximum wait.

Returns:
int

Return Code.

str

Error Message.

openmdao.utils.shell_proc.check_call(args, stdin=None, stdout=None, stderr=None, env=None, poll_delay=0.0, timeout=0.0)[source]

Run command with arguments.

Raises CalledProcessError if process returns an error code.

Parameters:
argsstr or list

If a string, then this is the command line to execute, and the subprocess.Popen shell argument is set True. Otherwise, this is a list of arguments; the first is the command to execute.

stdinstr, file, or int

Specify handling of stdin stream. If a string, a file of that name is opened. Otherwise, see the subprocess documentation.

stdoutstr, file, or int

Specify handling of stdout stream. If a string, a file of that name is opened. Otherwise, see the subprocess documentation.

stderrstr, file, or int

Specify handling of stderr stream. If a string, a file of that name is opened. Otherwise, see the subprocess documentation.

envdict

Environment variables for the command.

poll_delayfloat (seconds)

Time to delay between polling for command completion. A value of zero uses an internal default.

timeoutfloat (seconds)

Maximum time to wait for command completion. A value of zero implies an infinite maximum wait.