katgpucbf.dsim.shared_array module
Shared memory arrays.
- class katgpucbf.dsim.shared_array.SharedArray(fd: int, shape: tuple[int, ...], dtype: DTypeLike)[source]
Bases:
objectAn array that can be passed to another process.
Unlike
multiprocessing.shared_memory, the shared memory used for this is not backed by a file, and so is guaranteed to be cleaned up when the processes involved die off, without the need for a manager process.This is UNIX (probably Linux) specific.
Do not construct directly. Instead, either use
create()to allocate a new array, ormultiprocessing.connection.Connection.recv()to construct a new reference to an existing array in another process.- close() → None[source]
Close the reference shared array and release the mapping.
Accessing the array after this will most likely crash. It is safe to call twice.
- classmethod create(name: str, shape: tuple[int, ...], dtype: DTypeLike) → SharedArray[source]
Create a new array from scratch.
- Parameters:
name – An arbitrary name to associate with the array. See
os.memfd_create().shape – Shape of the array. To simplify this function, it requires a tuple (a scalar cannot be used).
dtype – The type of the array.