This package provides a drop-in replacement for the Python multiprocessing Queue class which handles transport of large numpy arrays. It avoids pickling and uses the multiprocessing Array class in the background. The major difference between this implementation and the normal queue is that the maximal amount of memory that the queue can have must be specified beforehand.
Attempting to send an array of a different shape or datatype of the previously inserted one resets the queue. Only passing of numpy arrays is supported, optionally annotated with timestamps if using the TimestampedArrayQueue class, but other object types can be supported by extending the class.
The package has been tested on Python 3.6/3/7 on Windows and MacOS and Linux with Travis. Python 2.7 is not supported.
fromarrayqueues.shared_arraysimportArrayQueuefrommultiprocessingimportProcessimportnumpyasnpclassReadProcess(Process):
def__init__(self, source_queue):
super().__init__()
self.source_queue=source_queuedefrun(self):
print(self.source_queue.get())
if__name__=="__main__":
q=ArrayQueue(1) # intitialises an ArrayQueue which can hold 1MB of datan=np.full((5,5), 5)
q.put(n)
r=ReadProcess(q)
r.start()
r.join()
Further examples can be found in tests.