jobflow_remote.utils.remote module#

class jobflow_remote.utils.remote.SharedHosts(*args, **kwargs)[source]#

Bases: object

A singleton context manager to allow sharing the same host objects.

Hosts are stored internally, associated to the worker name Being a singleton, opening the context manager multiple times allows to share the hosts across different sections of the code, if needed. Hosts connections are all closed only when leaving the last context manager.

A single project can be active at a time: the project is bound when the outermost context is opened and released when the last one is closed. Opening a nested context for a different project raises an error, since sharing host connections across projects is not supported.

Examples

>>> with SharedHosts(project) as shared_hosts:
...     host = shared_hosts.get_host("worker_name")
...     # Use host as required
Parameters:

project – The project configuration.

close_hosts() None[source]#

Close the connection to all the connected hosts

get_host(worker: str) BaseHost[source]#

Return the shared host, if already defined, otherwise retrieve the host from the project and connect it.

Parameters:

worker – The name of a worker defined in the project

Returns:

The shared host.

Return type:

BaseHost

exception jobflow_remote.utils.remote.UnsafeDeletionError[source]#

Bases: Exception

Error to signal that Job files could not be deleted as the safety check did not pass.

jobflow_remote.utils.remote.safe_remove_job_files(host: BaseHost, run_dir: str | Path | None, raise_on_error: bool = False) bool[source]#