> This page is for version 0.5.1.
> 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.

# nemo_gym.utils.http_deadline

An HTTP GET that ends at a total time limit.

## Module Contents

### Classes

| Name                                                                 | Description                                                                                              |
| -------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- |
| [`_Sockets`](#nemo_gym-utils-http_deadline-_Sockets)                 | The sockets of one request. `shutdown` ends any read blocked on them, and a socket opened afterwards.    |
| [`_TrackingAdapter`](#nemo_gym-utils-http_deadline-_TrackingAdapter) | An adapter whose connections report their sockets, so that a request can be stopped from another thread. |

### Functions

| Name                                                                       | Description                                                                                                 |
| -------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
| [`get_within_deadline`](#nemo_gym-utils-http_deadline-get_within_deadline) | GET `url` and return its status code and body, raising `TimeoutError` when `timeout_s` seconds have passed. |

### API

```python
class nemo_gym.utils.http_deadline._Sockets()
```

The sockets of one request. `shutdown` ends any read blocked on them, and a socket opened afterwards.

**`_lock`** `= threading.Lock()`

---

**`_sockets`** `list[socket] = []`

---

```python
nemo_gym.utils.http_deadline._Sockets._shutdown_one(
    sock: socket.socket
) -> None
```

staticmethod

```python
nemo_gym.utils.http_deadline._Sockets.add(
    sock: socket.socket
) -> None
```

```python
nemo_gym.utils.http_deadline._Sockets.shutdown() -> None
```

```python
class nemo_gym.utils.http_deadline._TrackingAdapter(
    sockets: nemo_gym.utils.http_deadline._Sockets
)
```

**Bases:** `HTTPAdapter`

An adapter whose connections report their sockets, so that a request can be stopped from another thread.

```python
nemo_gym.utils.http_deadline._TrackingAdapter._tracked_pool_classes() -> dict[str, type]
```

```python
nemo_gym.utils.http_deadline._TrackingAdapter.init_poolmanager(
    args: typing.Any = (),
    kwargs: typing.Any = {}
) -> None
```

```python
nemo_gym.utils.http_deadline._TrackingAdapter.proxy_manager_for(
    args: typing.Any = (),
    kwargs: typing.Any = {}
) -> typing.Any
```

```python
nemo_gym.utils.http_deadline.get_within_deadline(
    url: str,
    timeout_s: float,
    read_timeout_s: float | None = None,
    read_body: bool = True
) -> tuple[int, bytes]
```

GET `url` and return its status code and body, raising `TimeoutError` when `timeout_s` seconds have passed.

A requests timeout bounds the wait for each read, not the whole call: a peer that keeps sending a byte inside it,
in the headers or in the body, keeps the call going. The request therefore runs on a daemon thread that the caller
stops waiting for at the limit. At the limit the request's sockets are shut down, which ends a read that is still
waiting, in the headers or in the body, so the thread and its connection are released promptly. With
`read_body=False` the body is not read and `b""` is returned: for a readiness check, the answer is the headers.

Exceptions of the request, such as `requests.ConnectionError`, are raised unchanged.