Skip to main content

shared_ndarray

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

Metadata

Release files for shared-ndarray 1.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for shared-ndarray 1.1.1
File Size Uploaded
shared-ndarray-1.1.1.tar.gz 3.3 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for shared-ndarray 1.1.1
File Interpreter ABI Platform
shared_ndarray-1.1.1-py3-none-any.whl Python 3 none any Details
shared_ndarray-1.1.1-py2-none-any.whl Python 2 none any Details

Total release size: 15.2 kB

Release files / shared-ndarray-1.1.1.tar.gz

Download URL shared-ndarray-1.1.1.tar.gz
Size 3.3 kB
Tags Source
SHA-256 checksum
How to use checksums
852c3ab6561a1ecdca2b61f7b4db75f406e276294b5862c256fc011fd4a20c57
BLAKE2b-256 checksum
How to use checksums
a7431f9892e66765507ebb3172e77481be4c1df1857842b07874712f57d22a3c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / shared_ndarray-1.1.1-py3-none-any.whl

Download URL shared_ndarray-1.1.1-py3-none-any.whl
Size 6.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
197cd7494c944025c8f7ed8488713d85c37a44d0db9c64f7db202c10ab1823b1
BLAKE2b-256 checksum
How to use checksums
d3b350b4b6ba6c040eb7a7ea9d1af1f07170b8d17fed0b20f9eee8bde0da9732
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / shared_ndarray-1.1.1-py2-none-any.whl

Download URL shared_ndarray-1.1.1-py2-none-any.whl
Size 6.0 kB
Tags Python 2
SHA-256 checksum
How to use checksums
e239c2543f3ade8c89de13cc48e815921378d3b33e6c38af476de49b444ddee0
BLAKE2b-256 checksum
How to use checksums
937e00cca6df00fb700b2606e66cd0ee001815a651733b4f39b4baea1cdec621
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

1.1.1 This release

3 release files

1.1

3 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page