Skip to navigation

nemo_gym.runtime_dir

View as Markdown

One directory per server process for its AF_UNIX sockets, removed when the process exits.

A server with several uvicorn workers coordinates them over sockets: its checkpoint coordinator’s, and each worker’s private session-routing socket. They all live in /tmp/ng-<pid>-<random>/, under /tmp rather than the configured temporary directory because AF_UNIX paths are limited to about 100 bytes and cluster temporary directories can be long.

A clean exit removes the directory. A killed process cannot, so each new directory first removes those left behind: a directory goes only when its owner process no longer exists and none of its sockets accepts a connection. The connection check keeps a live server’s directory when the process check is wrong, as it is for a server in another PID namespace that shares /tmp, so a directory is never removed by age.

Module Contents

Functions

NameDescription
_any_socket_accepts-
_process_exists-
_remove-
remove_stale_runtime_dirsRemove this user’s runtime directories whose process is gone and whose sockets are all closed.
server_runtime_dirThis process’s runtime directory, created on first use.

Data

RUNTIME_ROOT

_CONNECT_TIMEOUT_SECONDS

_NAME

_runtime_dir

API

nemo_gym.runtime_dir._any_socket_accepts(
directory: str
) -> bool
nemo_gym.runtime_dir._process_exists(
pid: int
) -> bool
nemo_gym.runtime_dir._remove(
pid: int,
path: str
) -> None
nemo_gym.runtime_dir.remove_stale_runtime_dirs(
root: typing.Optional[str] = None
) -> list[str]

Remove this user’s runtime directories whose process is gone and whose sockets are all closed.

nemo_gym.runtime_dir.server_runtime_dir() -> str

This process’s runtime directory, created on first use.

nemo_gym.runtime_dir.RUNTIME_ROOT = '/tmp'
nemo_gym.runtime_dir._CONNECT_TIMEOUT_SECONDS = 0.5
nemo_gym.runtime_dir._NAME = re.compile('ng-(?P<pid>\\d+)-[0-9a-f]{8}')
nemo_gym.runtime_dir._runtime_dir: Optional[tuple[int, str]] = None