execute

qcengine.util.execute(command: List[str], infiles: Optional[Dict[str, str]] = None, outfiles: Optional[List[str]] = None, *, as_binary: Optional[List[str]] = None, scratch_name: Optional[str] = None, scratch_directory: Optional[str] = None, scratch_suffix: Optional[str] = None, scratch_messy: bool = False, scratch_exist_ok: bool = False, blocking_files: Optional[List[str]] = None, timeout: Optional[int] = None, interupt_after: Optional[int] = None, environment: Optional[Dict[str, str]] = None, shell: Optional[bool] = False) → Tuple[bool, Dict[str, Any]][source]

Runs a process in the background until complete.

Returns True if exit code zero

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.

Raises

FileExistsError – If any file in blocking is present

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)