multiprocessing.shared_memory in Python#

Vineyard offers a shared memory interface through SharedMemory and ShareableList classes, ensuring compatibility with Python’s multiprocessing.shared_memory.

Utilize the shared memory interface as demonstrated below:

>>> from vineyard import shared_memory
>>> value = shared_memory.ShareableList(client, [b"a", "bb", 1234, 56.78, True])
>>> value
ShareableList([b'a', 'bb', 1234, 56.78, True], name='o8000000119aa10c0')
>>> value[4] = False
>>> value
ShareableList([b'a', 'bb', 1234, 56.78, False], name='o8000000119aa10c0')


Please be aware that the semantics of Vineyard’s shared_memory differ slightly from those of Python’s multiprocessing module’s shared_memory. In Vineyard, shared memory cannot be modified once it becomes visible to other clients.

We have added a freeze method to make such transformation happen:

>>> value.freeze()

After being frozen, the shared memory (aka. the ShareableList in this case) is available for other clients:

>>> value1 = shared_memory.ShareableList(client,
>>> value1
ShareableList([b'a', 'bb', 1234, 56.78, False], name='o8000000119aa10c0')

For more details, see Shared memory.