Fast multiprocessing FIFO buffer (queue) for numpy arrays
Project description
ArrayFIFO
A FIFO buffer (queue) for efficient sharing of numpy arrays between multiple processes. Faster than multiprocessing.Queue because it uses shared memeory as a ring buffer, rather than pickling data and sending it over slow pipes.
Inspired by ArrayQueues. ArrayFIFO uses locks to support more than one producer and comsumer process, and it supports arrays whose shape and dtype can change arbitrarily with every put
call.
Usage example
import numpy as np
from multiprocessing import Process
from arrayfifo import ArrayFIFO
def produce(queue):
for i in range(20):
random_shape = np.random.randint(5,10, size=3)
array = np.random.randn(*random_shape)
queue.put(array, meta=i)
print(f'produced {type(array)} {array.shape} {array.dtype}; meta: {i}; hash: {hash(array.tobytes())}\n')
def consume(queue, pid):
while True:
array, meta = queue.get()
print(f'consumer {pid} consumed {type(array)} {array.shape} {array.dtype}; meta: {meta}; hash: {hash(array.tobytes())}\n')
queue = ArrayFIFO(bytes=10e6)
producer = Process(target=produce, args=(queue,))
consumers = [Process(target=consume, args=(queue, pid)) for pid in range(3)]
for c in consumers:
c.start()
producer.start()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
arrayfifo-0.0.3.tar.gz
(3.9 kB
view details)
Built Distribution
File details
Details for the file arrayfifo-0.0.3.tar.gz
.
File metadata
- Download URL: arrayfifo-0.0.3.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7159ce546c05e85f8c15637a2789cbfbe1fc25307a463666e4f9d5e1f0995e7c |
|
MD5 | 4f1970c31371f75acfe014975f7a3dcd |
|
BLAKE2b-256 | 95caabf98dc8d0b4f95f9b7c668b3a9b6e9ff4d7b1a59772ec456afca832e663 |
File details
Details for the file arrayfifo-0.0.3-py3-none-any.whl
.
File metadata
- Download URL: arrayfifo-0.0.3-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 916b2644805b94b676d26dcf98a449a17f338685150dd5b5f327d14a4265637e |
|
MD5 | f82da533e2505df08bbb1a547ca4852b |
|
BLAKE2b-256 | e361dc57a5460a7ed5c3698b3841c61d973e900c236ea193d72871c767dfa57c |