aitune.utils.monitoring.hardware_metrics.ipc

View as Markdown

Inter-process communication utilities.

Module Contents

Classes

NameDescription
ChildIpcSimple inter-process communication class to send and receive data between parent and child processes.
IpcErrorException for IPC errors.
ParentIpcSimple inter-process communication class to send and receive data between parent and child processes.

Functions

NameDescription
_read_exactlyRead exactly n bytes from stream, looping until all bytes are received.

API

class aitune.utils.monitoring.hardware_metrics.ipc.ChildIpc()

Simple inter-process communication class to send and receive data between parent and child processes.

This is implementation for child process. It uses stdin/stdout pipes to send and receive data which is packed using pickle.

stdin_raw
= sys.stdin.buffer
stdout_raw
= sys.stdout.buffer
aitune.utils.monitoring.hardware_metrics.ipc.ChildIpc.receive()

Receive data from the parent process.

Returns:

The data received from the parent process.

Raises:

  • ValueError: If the parent process closed the pipe.
aitune.utils.monitoring.hardware_metrics.ipc.ChildIpc.send(
data
)

Send data to the parent process.

Parameters:

data

The data to send to the parent process.

Returns:

The number of bytes sent.

class aitune.utils.monitoring.hardware_metrics.ipc.IpcError()
Exception

Bases: Exception

Exception for IPC errors.

class aitune.utils.monitoring.hardware_metrics.ipc.ParentIpc(
child_script,
flush_interval = 10
)

Simple inter-process communication class to send and receive data between parent and child processes.

This is implementation for parent process. It uses stdin/stdout pipes to send and receive data which is packed using pickle.

Note: there is assumption that parent will sent lots of small data, that is why flush_interval is used so that underlying operating system can buffer data and send it in larger chunks which improves throughput.

child
counter
= 0
aitune.utils.monitoring.hardware_metrics.ipc.ParentIpc.flush()

Flush the data to the child process.

aitune.utils.monitoring.hardware_metrics.ipc.ParentIpc.receive()

Receive data from the child process.

aitune.utils.monitoring.hardware_metrics.ipc.ParentIpc.send(
data
)

Send data to the child process.

Parameters:

data

The data to send to the child process.

Returns:

The number of bytes sent.

aitune.utils.monitoring.hardware_metrics.ipc._read_exactly(
stream,
n: int
) -> bytes

Read exactly n bytes from stream, looping until all bytes are received.