Skip to main content

Fast multiprocessing FIFO buffer (queue) for numpy arrays

Project description

Python Version PyPI version License: MIT

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


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)

Uploaded Source

Built Distribution

arrayfifo-0.0.3-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

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

Hashes for arrayfifo-0.0.3.tar.gz
Algorithm Hash digest
SHA256 7159ce546c05e85f8c15637a2789cbfbe1fc25307a463666e4f9d5e1f0995e7c
MD5 4f1970c31371f75acfe014975f7a3dcd
BLAKE2b-256 95caabf98dc8d0b4f95f9b7c668b3a9b6e9ff4d7b1a59772ec456afca832e663

See more details on using hashes here.

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

Hashes for arrayfifo-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 916b2644805b94b676d26dcf98a449a17f338685150dd5b5f327d14a4265637e
MD5 f82da533e2505df08bbb1a547ca4852b
BLAKE2b-256 e361dc57a5460a7ed5c3698b3841c61d973e900c236ea193d72871c767dfa57c

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