portugueslab / arrayqueues Goto Github PK
View Code? Open in Web Editor NEWMultiprocessing queues for numpy arrays using shared memory
License: MIT License
Multiprocessing queues for numpy arrays using shared memory
License: MIT License
If I try to create a queue of 30 frames for a video that has a resolution of 1080p60 (1920x1080), the code never runs. I'm assuming that's stuck trying to allocate that much memory (I tried running this with SimpleQueue originally and had the same issue).
how can i put dict objects into array?
I was curious to know, if the items that needs to be added are already known in advance (shape and type) would it be technically possible to somehow utilize this information to increase the speed of the data transfer ? (If I tweak the code or whatnot)
Thanks
Hello!
I wanted to know, when adding an element to a queue that is full, like in this test:
def test():
shape = (100, 100)
num_elements = 10
data = np.random.random(size=shape)
mbytes = data.nbytes/1_000_000*num_elements
queue = ArrayQueue(max_mbytes=mbytes)
for i in range(2*num_elements):
print(i)
queue.put(data)
Instead of throwing an error :
Traceback (most recent call last):
File "D:/Thomas/Python/treequeues/test_treequeues.py", line 99, in <module>
test()
File "D:/Thomas/Python/treequeues/test_treequeues.py", line 77, in test
queue.put(data)
File "D:\Thomas\Python\treequeues\venv\lib\site-packages\arrayqueues\shared_arrays.py", line 87, in put
self.check_full()
File "D:\Thomas\Python\treequeues\venv\lib\site-packages\arrayqueues\shared_arrays.py", line 73, in check_full
raise Full(
queue.Full: Queue of length 10 full when trying to insert 0, last item read was 0
Would it be possible to be able to hang like multprocessing queue ?
Hi! I think you're project is very convenient for putting numpy arrays into threads.
However, I have noticed a bug that is slightly annoying. Calling ArrayQueue.get() does not truly clear the array out. Trying to insert an array of the same size back into a "cleared" array results in a memory error. Check out the code below: ArrayQueue.empty() returns true, even though the array is not truly cleared.
from arrayqueues.shared_arrays import ArrayQueue
import threading
import numpy as np
import time
class ReadProcess(threading.Thread):
def __init__(self, queue):
super().__init__()
self.queue = queue
def run(self):
a = self.queue.get()
print("Is queue empty (from child thread): {}".format(queue.empty()))
if __name__ == "__main__":
create_start = time.time()
queue = ArrayQueue(8/1000) # intitialises an ArrayQueue which can hold 8 KB of data
numbers = np.random.uniform(10000, size = 1000)
numbers_copy = np.copy(numbers)
queue.put(numbers_copy)
thread = ReadProcess(queue)
thread.start()
thread.join()
print("Is queue empty(from main thread): {}".format(queue.empty()))
queue.put(numbers_copy)
queue.get()
create_end = time.time()
print("execution time: {}".format(create_end - create_start))
Here is the output of the error:
Is queue empty (from child thread): True
Is queue empty(from main thread): True
Traceback (most recent call last):
File "array_queue_bug.py", line 25, in
queue.put(numbers_copy)
File "C:\Users\jjones\AppData\Local\Programs\Python\Python37\lib\site-packages\arrayqueues\shared_arrays.py", line 71, in put
self.check_full()
File "C:\Users\jjones\AppData\Local\Programs\Python\Python37\lib\site-packages\arrayqueues\shared_arrays.py", line 63, in check_full
self.view.i_item, self.last_item))
queue.Full: Queue of length 1 full when trying to insert 0, last item read was 0
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.