mlos_bench.services.local.local_exec module¶
Helper functions to run scripts and commands locally on the scheduler side.
- class mlos_bench.services.local.local_exec.LocalExecService(config: Dict[str, Any] | None = None, global_config: Dict[str, Any] | None = None, parent: Service | None = None, methods: Dict[str, Callable] | List[Callable] | None = None)¶
Bases:
TempDirContextService
,SupportsLocalExec
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.
- Attributes:
config_loader_service
Return a config loader service.
Methods
export
()Return a dictionary of functions available in this service.
local_exec
(script_lines[, env, cwd])Execute the script lines from script_lines in a local process.
merge_methods
(ext_methods, local_methods)Merge methods from the external caller with the local ones.
new
(class_name[, config, global_config, parent])Factory method for a new service with a given config.
pprint
()Produce a human-readable string listing all public methods of the service.
register
(services)Register new mix-in services.
temp_dir_context
([path])Create a temp directory or use the provided path.
- local_exec(script_lines: Iterable[str], env: Mapping[str, TunableValue] | 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.
- mlos_bench.services.local.local_exec.split_cmdline(cmdline: str) Iterable[List[str]] ¶
A single command line may contain multiple commands separated by special characters (e.g., &&, ||, etc.) so further split the commandline into an array of subcommand arrays.
- Parameters:
- cmdline: str
The commandline to split.
- Yields:
- Iterable[List[str]]
A list of subcommands or separators, each one a list of tokens. Can be rejoined as a flattened array.