Skip to navigation

nemo_gym.orchestration.executors.connection

View as MarkdownOpen in Claude

Module Contents

Classes

NameDescription
Connection-
LocalConnection-
SSHConnectionSingle SSH master connection; copy and all commands reuse the same socket.

Functions

NameDescription
_checked-
_checked_holding_inputLike _checked, but stdin stays open until the command exits, so its EOF on the far end means that this
_positive_int_from_env-
_read_stderr_forwarding_progressKeep all of stderr for the error message, and pass each progress line on as it arrives.
_reap_in_backgroundReap a stopped command and close its pipes once the threads using them are done, without delaying the caller.
_run_stopping_group_on_timeoutsubprocess.run(capture_output=True, text=True, timeout=timeout_s), but an expiry kills the command’s whole
get_connection-

Data

READER_PROGRESS_PREFIX

SSH_COMMAND_TIMEOUT_ENV

SSH_CONNECT_TIMEOUT_ENV

SSH_SERVER_ALIVE_COUNT_ENV

SSH_SERVER_ALIVE_INTERVAL_ENV

API

class nemo_gym.orchestration.executors.connection.Connection()
Abstract
nemo_gym.orchestration.executors.connection.Connection.__exit__(
_ = ()
) -> None
nemo_gym.orchestration.executors.connection.Connection.close() -> None
nemo_gym.orchestration.executors.connection.Connection.copy(
local: pathlib.Path,
remote: pathlib.Path
) -> None
abstract
nemo_gym.orchestration.executors.connection.Connection.run(
commands: list[str]
) -> str
abstract
nemo_gym.orchestration.executors.connection.Connection.write_text(
remote: pathlib.Path,
content: str,
private: bool = False
) -> None
abstract
class nemo_gym.orchestration.executors.connection.LocalConnection()

Bases: Connection

nemo_gym.orchestration.executors.connection.LocalConnection.copy(
local: pathlib.Path,
remote: pathlib.Path
) -> None
nemo_gym.orchestration.executors.connection.LocalConnection.run(
commands: list[str]
) -> str
nemo_gym.orchestration.executors.connection.LocalConnection.run_with_input_held(
commands: list[str]
) -> str
nemo_gym.orchestration.executors.connection.LocalConnection.write_text(
remote: pathlib.Path,
content: str,
private: bool = False
) -> None
class nemo_gym.orchestration.executors.connection.SSHConnection(
hostname: str
)

Bases: Connection

Single SSH master connection; copy and all commands reuse the same socket.

The environment variables above bound a connection that hangs: a login host that never answers the connect, a link that goes quiet, or a command that never finishes, the remote reader included. A command that runs out of its time raises RuntimeError.

_MASTER_TIMEOUT
= 10
_OPTS
_command_timeout_s
= _positive_int_from_env(SSH_COMMAND_TIMEOUT_ENV)
_master
Popen | None = None
_opts
= list(self._OPTS)
_socket
nemo_gym.orchestration.executors.connection.SSHConnection._ssh_opts() -> list[str]
nemo_gym.orchestration.executors.connection.SSHConnection._wait_for_socket() -> None
nemo_gym.orchestration.executors.connection.SSHConnection.close() -> None
nemo_gym.orchestration.executors.connection.SSHConnection.copy(
local: pathlib.Path,
remote: pathlib.Path
) -> None
nemo_gym.orchestration.executors.connection.SSHConnection.run(
commands: list[str]
) -> str
nemo_gym.orchestration.executors.connection.SSHConnection.run_with_input_held(
commands: list[str]
) -> str
nemo_gym.orchestration.executors.connection.SSHConnection.write_text(
remote: pathlib.Path,
content: str,
private: bool = False
) -> None
nemo_gym.orchestration.executors.connection._checked(
cmd: list[str],
input: str | None = None,
context: str = '',
timeout_s: float | None = None
) -> str
nemo_gym.orchestration.executors.connection._checked_holding_input(
cmd: list[str],
input: str,
context: str = '',
timeout_s: float | None = None
) -> str

Like _checked, but stdin stays open until the command exits, so its EOF on the far end means that this process or its connection is gone. The commands must end the remote shell themselves (exit).

Progress lines on the command’s stderr (READER_PROGRESS_PREFIX) reach this process’s stderr while it runs; stdout is returned whole, as before. A command still running after timeout_s seconds is killed, which closes its stdin and ends the remote shell as any other interruption does, and raises RuntimeError; None sets no limit.

nemo_gym.orchestration.executors.connection._positive_int_from_env(
name: str
) -> int | None
nemo_gym.orchestration.executors.connection._read_stderr_forwarding_progress(
stream,
output: dict[str, str]
) -> None

Keep all of stderr for the error message, and pass each progress line on as it arrives.

nemo_gym.orchestration.executors.connection._reap_in_background(
process: subprocess.Popen,
threads: list[threading.Thread]
) -> None

Reap a stopped command and close its pipes once the threads using them are done, without delaying the caller.

Closing a pipe while a thread still reads or writes it would block on that thread, which is the overrun the deadline exists to prevent, so the close waits for each thread (they end because the command was killed).

nemo_gym.orchestration.executors.connection._run_stopping_group_on_timeout(
cmd: list[str],
input: str | None,
timeout_s: float
) -> subprocess.CompletedProcess[str]

subprocess.run(capture_output=True, text=True, timeout=timeout_s), but an expiry kills the command’s whole process group, so what it started (an ssh ProxyCommand, an rsync helper) does not outlive the error.

nemo_gym.orchestration.executors.connection.get_connection(
hostname: str | None
nemo_gym.orchestration.executors.connection.READER_PROGRESS_PREFIX = 'gym-reader progress:'
nemo_gym.orchestration.executors.connection.SSH_COMMAND_TIMEOUT_ENV = 'NEMO_GYM_SSH_COMMAND_TIMEOUT_S'
nemo_gym.orchestration.executors.connection.SSH_CONNECT_TIMEOUT_ENV = 'NEMO_GYM_SSH_CONNECT_TIMEOUT_S'
nemo_gym.orchestration.executors.connection.SSH_SERVER_ALIVE_COUNT_ENV = 'NEMO_GYM_SSH_SERVER_ALIVE_COUNT_MAX'
nemo_gym.orchestration.executors.connection.SSH_SERVER_ALIVE_INTERVAL_ENV = 'NEMO_GYM_SSH_SERVER_ALIVE_INTERVAL_S'