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()
Metadata
Release files for arrayfifo 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| arrayfifo-0.0.3.tar.gz | 3.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| arrayfifo-0.0.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.1 kB
Release files / arrayfifo-0.0.3.tar.gz
| Download URL | arrayfifo-0.0.3.tar.gz |
|---|---|
| Size | 3.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7159ce546c05e85f8c15637a2789cbfbe1fc25307a463666e4f9d5e1f0995e7c
|
|
BLAKE2b-256 checksum How to use checksums |
95caabf98dc8d0b4f95f9b7c668b3a9b6e9ff4d7b1a59772ec456afca832e663
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.9.19
|
Release files / arrayfifo-0.0.3-py3-none-any.whl
| Download URL | arrayfifo-0.0.3-py3-none-any.whl |
|---|---|
| Size | 4.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
916b2644805b94b676d26dcf98a449a17f338685150dd5b5f327d14a4265637e
|
|
BLAKE2b-256 checksum How to use checksums |
e361dc57a5460a7ed5c3698b3841c61d973e900c236ea193d72871c767dfa57c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.9.19
|