katgpucbf.dsim.shared_array module
Shared memory arrays.
- class katgpucbf.dsim.shared_array.SharedArray(fd: int, shape: tuple[int, ...], dtype: dtype[Any] | None | type[Any] | _SupportsDType[dtype[Any]] | str | tuple[Any, int] | tuple[Any, SupportsIndex | Sequence[SupportsIndex]] | list[Any] | _DTypeDict | tuple[Any, Any])[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: dtype[Any] | None | type[Any] | _SupportsDType[dtype[Any]] | str | tuple[Any, int] | tuple[Any, SupportsIndex | Sequence[SupportsIndex]] | list[Any] | _DTypeDict | tuple[Any, Any]) → 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.