> For clean Markdown content of this page, append .md to this URL.

# aitune.utils.monitoring.hardware_metrics.parent_receiver

Parent receiver for hardware metrics.

## Module Contents

### Classes

| Name                                                                                         | Description                                                             |
| -------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------- |
| [`ParentReceiver`](#aitune-utils-monitoring-hardware_metrics-parent_receiver-ParentReceiver) | Receiver which gets metrics from queue and sends them to child process. |

### API

```python
class aitune.utils.monitoring.hardware_metrics.parent_receiver.ParentReceiver(
    queue: queue.Queue | multiprocessing.queues.Queue
)
```

Receiver which gets metrics from queue and sends them to child process.

Communication uses pickle to serialize and deserialize data and sends/receives data via a stdin/stdout pipe.

If the main process dies, the child process will dump the collected metrics to a CSV file.
If the main process is still alive and requests the metrics back, the child process will send them as pandas DataFrame so
that it takes less memory to send them back.

**Parameters:**

**`queue`** `Queue | multiprocessing.queues.Queue`

The queue to send the metrics to.

---

**`keep_running`** `= threading.Event()`

---

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

---

```python
aitune.utils.monitoring.hardware_metrics.parent_receiver.ParentReceiver.get_metrics() -> pandas.DataFrame
```

Gets the metrics.

**Returns:** `pd.DataFrame`

The metrics as a pandas DataFrame.

**Raises:**

* `RuntimeError`: If the receiver is not started.

```python
aitune.utils.monitoring.hardware_metrics.parent_receiver.ParentReceiver.run()
```

Runs the receiver.

This method is run in a separate thread.

```python
aitune.utils.monitoring.hardware_metrics.parent_receiver.ParentReceiver.snapshot(
    path: pathlib.Path,
    reset_metrics: bool = True
) -> None
```

Dumps currently collected metrics to a file.

**Parameters:**

**`path`** `Path`

Path to write the CSV file.

---

**`reset_metrics`** `bool` — default: True

If True, clears the accumulated metrics after writing.

---

**Raises:**

* `RuntimeError`: If the receiver is not started.

```python
aitune.utils.monitoring.hardware_metrics.parent_receiver.ParentReceiver.start()
```

Starts the receiver.

```python
aitune.utils.monitoring.hardware_metrics.parent_receiver.ParentReceiver.stop()
```

Stops the receiver.