mlos_bench.services.types.local_exec_type module¶
Protocol interface for Service types that provide helper functions to run scripts and commands locally on the scheduler side.
- class mlos_bench.services.types.local_exec_type.SupportsLocalExec(*args, **kwargs)¶
Bases:
Protocol
Protocol interface for a collection of methods to run scripts and commands in an external process on the node acting as the scheduler.
Can be useful for data processing due to reduced dependency management complications vs the target environment. Used in LocalEnv and provided by LocalExecService.
Methods
local_exec
(script_lines[, env, cwd])Execute the script lines from script_lines in a local process.
temp_dir_context
([path])Create a temp directory or use the provided path.
- local_exec(script_lines: Iterable[str], env: Mapping[str, int | float | str | None] | None = None, cwd: str | None = None) Tuple[int, str, str] ¶
Execute the script lines from script_lines in a local process.
- Parameters:
- script_linesIterable[str]
Lines of the script to run locally. Treat every line as a separate command to run.
- envMapping[str, Union[int, float, str]]
Environment variables (optional).
- cwdstr
Work directory to run the script at. If omitted, use temp_dir or create a temporary dir.
- Returns:
- (return_code, stdout, stderr)(int, str, str)
A 3-tuple of return code, stdout, and stderr of the script process.
- temp_dir_context(path: str | None = None) TemporaryDirectory | nullcontext ¶
Create a temp directory or use the provided path.
- Parameters:
- pathstr
A path to the temporary directory. Create a new one if None.
- Returns:
- temp_dir_contextTemporaryDirectory
Temporary directory context to use in the with clause.