Skip to main content

Pipe-like API over multiprocessing.shared_memory for fast numpy array transfer between processes.

Project description

mempipe

This package combines the simplicity of using Python's multiprocessing.Pipe() with the speed of multiprocessing.shared_memory.SharedMemory. Meant for a multiprocessing data analysis pipeline where each process analyses the data and passes it to the next process for the next step.

The passed data can only be a numpy array.

Originally designed for a real-time Brain-Computer-Interface application.

Install

Using uv:

uv sync         # set up the environment
uv run pytest   # run the tests

How to use

Import the MemPipe class. Make an instance object. Call YourMemPipeInstance.Pipe(ex_array) instead of the multiprocessing.Pipe(duplex=False) in your applicaiton. The ex_array is a numpy array that is used to infer the dtype and the size of the shared memory. It must be the biggest array size that you will intend to pass between the processes. If you .send() larger numpy arrays, they will be truncated to ex_array.shape. If you .send() smaller numpy arrays, they will be handled just fine.

The pipe objects support poll(), recv(), and send(). Before calling recv(), you must call poll() and make sure it returns True (as you would normally).

All else is handled internally.
Currently, ./tests/test2.py shows an example using the latest API.

Simulation

This was done using an older version of the package

My simple simulation (found here: ./tests/test3.py) shows that passing a numpy array of $12000 \times 4000$ is much faster this way, compared to regular pipes.

a figure
20 repeatitions on the x-axis, and the execution time on the y-axis.

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

mempipe-0.3.2.tar.gz (92.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mempipe-0.3.2-py3-none-any.whl (28.7 kB view details)

Uploaded Python 3

File details

Details for the file mempipe-0.3.2.tar.gz.

File metadata

  • Download URL: mempipe-0.3.2.tar.gz
  • Upload date:
  • Size: 92.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mempipe-0.3.2.tar.gz
Algorithm Hash digest
SHA256 96c7569d217c7e6299a841bbb8c1ccb31dd6d2ab094d6a3980a265cb6cb659ef
MD5 c86af4f8eb8c0e4e14616d7cb198cbc5
BLAKE2b-256 894e30aca43c7bb7913525f9b9a8c0d12edc5deb13494f4f7bda565fcb84ecb3

See more details on using hashes here.

Provenance

The following attestation bundles were made for mempipe-0.3.2.tar.gz:

Publisher: publish.yml on AtMostafa/mempipe

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mempipe-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: mempipe-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 28.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mempipe-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ab2df272bc38f5d4b16f5b8885a438861d4c62a7ba5d0af0cb61dec6e1669f22
MD5 7327b3bdc4a49f985367bc6c1bbea1b0
BLAKE2b-256 8f87e532ac909e5ecfbded14bd5d60e132375cfae3b4c7f635e95a8719553e5d

See more details on using hashes here.

Provenance

The following attestation bundles were made for mempipe-0.3.2-py3-none-any.whl:

Publisher: publish.yml on AtMostafa/mempipe

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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