grain.multiprocessing.SharedMemoryArray

grain.multiprocessing.SharedMemoryArray#

class grain.multiprocessing.SharedMemoryArray(shape, dtype=<class 'float'>)#

A NumPy array subclass which is backed by shared memory.

This should be used in combination with Python multiprocessing. Compared with the normal NumPy ndarray it avoids expensive serialization when sending the array to another Python process (on the same machine). It also doesn’t require a copy on the receiving side.

The last processes using the array must call unlink_on_del()! Otherwise the memory will not be freed.

Parameters:
  • shape (Iterable[int])

  • dtype (npt.DTypeLike)

__init__(*args, **kwargs)#
Parameters:
  • args (Any)

  • kwargs (Any)

Return type:

None

Methods

__init__(*args, **kwargs)

close_shm_async(shm, unlink)

enable_async_del([num_threads, ...])

Enables asynchronous deletion of shared memory arrays.

from_metadata(metadata)

from_shared_memory(shm, shape, dtype)

unlink_on_del()

Mark this object responsible for unlinking the shared memory.

Attributes

metadata