Skip to main content

A pickleable wrapper for sharing NumPy ndarrays between processes using POSIX shared memory.

Project description

A pickleable wrapper for sharing NumPy ndarrays between processes using POSIX shared memory.

SharedNDArrays are designed to be sent over multiprocessing.Pipe and Queue without serializing or transmitting the underlying ndarray or buffer. While the associated file descriptor is closed when the SharedNDArray is garbage collected, the underlying buffer is not released when the process ends: you must manually call the unlink() method from the last process to use it.

Usage

from __future__ import print_function

import multiprocessing as mp

import numpy as np
from shared_ndarray import SharedNDArray

try:
    shm = SharedNDArray((4, 4))
    shm.array[0, 0] = 1
    p = mp.Process(target=lambda shm: print(shm.array), args=(shm,))
    p.start()
    p.join()
finally:
    shm.unlink()

This should print:

[[ 1.  0.  0.  0.]
 [ 0.  0.  0.  0.]
 [ 0.  0.  0.  0.]
 [ 0.  0.  0.  0.]]

There are also convenience methods to create a new SharedNDArray from an existing NumPy array:

arr = np.array([0, 0])
shm1 = SharedNDArray.copy(arr)
shm2 = SharedNDArray.zeros_like(arr)
shm1.unlink()
shm2.unlink()

Dependencies

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

shared-ndarray-1.1.1.tar.gz (3.3 kB view details)

Uploaded Source

Built Distributions

shared_ndarray-1.1.1-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

shared_ndarray-1.1.1-py2-none-any.whl (6.0 kB view details)

Uploaded Python 2

File details

Details for the file shared-ndarray-1.1.1.tar.gz.

File metadata

File hashes

Hashes for shared-ndarray-1.1.1.tar.gz
Algorithm Hash digest
SHA256 852c3ab6561a1ecdca2b61f7b4db75f406e276294b5862c256fc011fd4a20c57
MD5 3c4c4488aac7275c26ea4f271294402f
BLAKE2b-256 a7431f9892e66765507ebb3172e77481be4c1df1857842b07874712f57d22a3c

See more details on using hashes here.

File details

Details for the file shared_ndarray-1.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for shared_ndarray-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 197cd7494c944025c8f7ed8488713d85c37a44d0db9c64f7db202c10ab1823b1
MD5 25d2f2e890ae0868b4bbe20b7ce87b5a
BLAKE2b-256 d3b350b4b6ba6c040eb7a7ea9d1af1f07170b8d17fed0b20f9eee8bde0da9732

See more details on using hashes here.

File details

Details for the file shared_ndarray-1.1.1-py2-none-any.whl.

File metadata

File hashes

Hashes for shared_ndarray-1.1.1-py2-none-any.whl
Algorithm Hash digest
SHA256 e239c2543f3ade8c89de13cc48e815921378d3b33e6c38af476de49b444ddee0
MD5 4e15569a533fb354a3e7c52a3df9b98c
BLAKE2b-256 937e00cca6df00fb700b2606e66cd0ee001815a651733b4f39b4baea1cdec621

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page