rex.utilities.execution.SubprocessManager

class SubprocessManager[source]

Bases: object

Base class to handle subprocess execution.

Methods

format_walltime(hours)

Get the SLURM walltime string in format "HH:MM:SS"

make_path(d)

Make a directory tree if it doesn't exist.

make_sh(fname, script)

Make a shell script (.sh file) to execute a subprocess.

rm(fname)

Remove a file.

s(s)

Format input as str w/ appropriate quote types for python cli entry.

submit(cmd[, background, background_stdout])

Open a subprocess and submit a command.

static make_path(d)[source]

Make a directory tree if it doesn’t exist.

Parameters

d (str) – Directory tree to check and potentially create.

static make_sh(fname, script)[source]

Make a shell script (.sh file) to execute a subprocess.

Parameters
  • fname (str) – Name of the .sh file to create.

  • script (str) – Contents to be written into the .sh file.

static rm(fname)[source]

Remove a file.

Parameters

fname (str) – Filename (with path) to remove.

static submit(cmd, background=False, background_stdout=False)[source]

Open a subprocess and submit a command.

Parameters
  • cmd (str) – Command to be submitted using python subprocess.

  • background (bool) – Flag to submit subprocess in the background. stdout stderr will be empty strings if this is True.

  • background_stdout (bool) – Flag to capture the stdout/stderr from the background process in a nohup.out file.

Returns

  • stdout (str) – Subprocess standard output. This is decoded from the subprocess stdout with rstrip.

  • stderr (str) – Subprocess standard error. This is decoded from the subprocess stderr with rstrip. After decoding/rstrip, this will be empty if the subprocess doesn’t return an error.

static s(s)[source]

Format input as str w/ appropriate quote types for python cli entry.

Examples

list, tuple -> “[‘one’, ‘two’]” dict -> “{‘key’: ‘val’}” int, float, None -> ‘0’ str, other -> ‘string’

static format_walltime(hours)[source]

Get the SLURM walltime string in format “HH:MM:SS”

Parameters

hours (float | int) – Requested number of job hours.

Returns

walltime (str) – SLURM walltime request in format “HH:MM:SS”