execute

qcengine.util.execute(command, infiles=None, outfiles=None, *, as_binary=None, scratch_name=None, scratch_directory=None, scratch_suffix=None, scratch_messy=False, scratch_exist_ok=False, blocking_files=None, timeout=None, interupt_after=None, environment=None, shell=False, exit_code=0)[source]

Runs a process in the background until complete.

Returns True if exit code <= exit_code (default 0)

Parameters:
  • command (list of str) –

  • infiles (Dict[str] = str) – Input file names (names, not full paths) and contents. to be written in scratch dir. May be {}.

  • outfiles (List[str] = None) – Output file names to be collected after execution into values. May be {}.

  • as_binary (List[str] = None) – Keys of infiles or outfiles to be treated as bytes.

  • scratch_name (str, optional) – Passed to temporary_directory

  • scratch_directory (str, optional) – Passed to temporary_directory

  • scratch_suffix (str, optional) – Passed to temporary_directory

  • scratch_messy (bool, optional) – Passed to temporary_directory

  • scratch_exist_ok (bool, optional) – Passed to temporary_directory

  • blocking_files (list, optional) – Files which should stop execution if present beforehand.

  • timeout (int, optional) – Stop the process after n seconds.

  • interupt_after (int, optional) – Interupt the process (not hard kill) after n seconds.

  • environment (dict, optional) – The environment to run in

  • shell (bool, optional) – Run command through the shell.

  • exit_code (int, optional) – The exit code above which the process is considered failure.

Raises:

FileExistsError – If any file in blocking is present

Return type:

Tuple[bool, Dict[str, Any]]

Examples

# execute multiple commands in same dir >>> success, dexe = qcng.util.execute([‘command_1’], infiles, [], scratch_messy=True) >>> success, dexe = qcng.util.execute([‘command_2’], {}, outfiles, scratch_messy=False, scratch_name=Path(dexe[‘scratch_directory’]).name, scratch_exist_ok=True)