> This page is for version 0.5.0.
> For other versions, use one of these documentation indexes:
> - Main (default): https://docs.nvidia.com/nemo/gym/main/llms.txt
> - 0.7.0: https://docs.nvidia.com/nemo/gym/v0.7.0/llms.txt
> - 0.6.0: https://docs.nvidia.com/nemo/gym/v0.6.0/llms.txt
> - 0.5.1: https://docs.nvidia.com/nemo/gym/v0.5.1/llms.txt
> - 0.5.0: https://docs.nvidia.com/nemo/gym/v0.5.0/llms.txt
> - 0.4.0: https://docs.nvidia.com/nemo/gym/v0.4.0/llms.txt
> - 0.3.0: https://docs.nvidia.com/nemo/gym/v0.3.0/llms.txt
> - 0.2.1: https://docs.nvidia.com/nemo/gym/v0.2.1/llms.txt

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/nemo/gym/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nvidia.com/nemo/gym/_mcp/server.

# nemo_gym.runtime_dir

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-&lt;pid&gt;-&lt;random&gt;/`,
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

| Name                                                                           | Description                                                                                    |
| ------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------- |
| [`_any_socket_accepts`](#nemo_gym-runtime_dir-_any_socket_accepts)             | -                                                                                              |
| [`_process_exists`](#nemo_gym-runtime_dir-_process_exists)                     | -                                                                                              |
| [`_remove`](#nemo_gym-runtime_dir-_remove)                                     | -                                                                                              |
| [`remove_stale_runtime_dirs`](#nemo_gym-runtime_dir-remove_stale_runtime_dirs) | Remove this user's runtime directories whose process is gone and whose sockets are all closed. |
| [`server_runtime_dir`](#nemo_gym-runtime_dir-server_runtime_dir)               | This process's runtime directory, created on first use.                                        |

### Data

[`RUNTIME_ROOT`](#nemo_gym-runtime_dir-RUNTIME_ROOT)

[`_CONNECT_TIMEOUT_SECONDS`](#nemo_gym-runtime_dir-_CONNECT_TIMEOUT_SECONDS)

[`_NAME`](#nemo_gym-runtime_dir-_NAME)

[`_runtime_dir`](#nemo_gym-runtime_dir-_runtime_dir)

### API

```python
nemo_gym.runtime_dir._any_socket_accepts(
    directory: str
) -> bool
```

```python
nemo_gym.runtime_dir._process_exists(
    pid: int
) -> bool
```

```python
nemo_gym.runtime_dir._remove(
    pid: int,
    path: str
) -> None
```

```python
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.

```python
nemo_gym.runtime_dir.server_runtime_dir() -> str
```

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

```python
nemo_gym.runtime_dir.RUNTIME_ROOT = '/tmp'
```

```python
nemo_gym.runtime_dir._CONNECT_TIMEOUT_SECONDS = 0.5
```

```python
nemo_gym.runtime_dir._NAME = re.compile('ng-(?P<pid>\\d+)-[0-9a-f]{8}')
```

```python
nemo_gym.runtime_dir._runtime_dir: Optional[tuple[int, str]] = None
```