rez.utils.execution#

Utilities related to process/script execution.

rez.utils.execution.add_sys_paths(paths)#

Add to sys.path, and revert on scope exit.

class rez.utils.execution.Popen#

Bases: Popen

subprocess.Popen wrapper.

It fixes some issues encountered in Maya and Katana (and potentially other DCCs) and also forces the encoding to be utf-8 if text=True or universal_newlines=True is set without specifying the encoding.

__init__(args, **kwargs)#

Create new Popen instance.

communicate(input=None, timeout=None)#

Interact with process: Send data to stdin and close it. Read data from stdout and stderr, until end-of-file is reached. Wait for process to terminate.

The optional “input” argument should be data to be sent to the child process, or None, if no data should be sent to the child. communicate() returns a tuple (stdout, stderr).

By default, all communication is in bytes, and therefore any “input” should be bytes, and the (stdout, stderr) will be bytes. If in text mode (indicated by self.text_mode), any “input” should be a string, and (stdout, stderr) will be strings decoded according to locale encoding, or by “encoding” if set. Text mode is triggered by setting any of text, encoding, errors or universal_newlines.

kill()#

Kill the process with SIGKILL

poll()#

Check if child process has terminated. Set and return returncode attribute.

send_signal(sig)#

Send a signal to the process.

terminate()#

Terminate the process with SIGTERM

property universal_newlines#
wait(timeout=None)#

Wait for child process to terminate; returns self.returncode.

class rez.utils.execution.ExecutableScriptMode#

Bases: Enum

Which scripts to create with util.create_executable_script.

single = 1#
py = 2#
platform_specific = 3#
both = 4#
rez.utils.execution.create_executable_script(filepath, body, program=None, py_script_mode=None)#

Create an executable script. In case a py_script_mode has been set to create a .py script the shell is expected to have the PATHEXT environment variable to include “.PY” in order to properly launch the command without the .py extension.

Parameters:
  • filepath (str) – File to create.

  • body (str or Callable) – Contents of the script. If a callable, its code is used as the script body.

  • program (str) – Name of program to launch the script. Default is ‘python’

  • py_script_mode (ExecutableScriptMode) – What kind of script to create. Defaults to rezconfig.create_executable_script_mode.

Returns:

List of filepaths of created scripts. This may differ from the supplied filepath depending on the py_script_mode

rez.utils.execution.create_forwarding_script(filepath, module, func_name, *nargs, **kwargs)#

Create a ‘forwarding’ script.

A forwarding script is one that executes some arbitrary Rez function. This is used internally by Rez to dynamically create a script that uses Rez, even though the parent environment may not be configured to do so.