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.tar.gz (3.3 kB view details)

Uploaded Source

Built Distributions

shared_ndarray-1.1-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

shared_ndarray-1.1-py2-none-any.whl (5.9 kB view details)

Uploaded Python 2

File details

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

File metadata

File hashes

Hashes for shared-ndarray-1.1.tar.gz
Algorithm Hash digest
SHA256 4c5c391e24d027a1275d0266bccf903aa1735f052a22329ef7fe934cb98e3d3d
MD5 a35b62d5210e6e32c3f4df1cadeb7037
BLAKE2b-256 7f36e367e8ea4f409cfcbc66ea296c35a3a567c40165b6637bd116a65737d6e2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for shared_ndarray-1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d1da8849b20e2c118e654d495b86fbebfc3b1dc3d1224ad3cf73c49c1dad081a
MD5 6a521c4929f549312577f57e97cb623d
BLAKE2b-256 b01fecba43c2073fa9c907ab2a5d6afc5cb3fa8e721ecb5be6f9ccf14b63e623

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for shared_ndarray-1.1-py2-none-any.whl
Algorithm Hash digest
SHA256 0499194b525fd96ba244d9bd158ab1377bd070be67bda08e15c57cfd71d98b79
MD5 49763d8da43b34159a3ae18c4edb39b4
BLAKE2b-256 018b393b32ef6c42486d392bb8efaab7a1472abf4ac173af5ffc510a763e727e

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