array.array()'s memory shared with multiprocessing.Process()

gerlando.falauto at gmail.com gerlando.falauto at gmail.com
Sun Sep 10 07:40:49 EDT 2017


> 
> I suspect it's down to timing.
> 
> What you're putting into the queue is a reference to the array, and it's 
> only some time later that the array itself is pickled and then sent (the 
> work being done in the 'background').
> 
> Modifying the array before (or while) it's actually being sent would 
> explain the problem you're seeing.

That would also have been my guess. However, according to documentation:

> When an object is put on a queue, the object is pickled and a background 
> thread later flushes the pickled data to an underlying pipe.

In my understanding this means the object is pickled *before* the background thread takes care of flushing the data to the pipe. Is that a mistake in the documentation then?

Any suggestion for a way to work around this limitation?
Or perhaps a different approach altogether I could use to reduce CPU load?
What the main thread actually does is dequeue data from a high-speed USB-to-serial (2.000.000 bps), that's why I came up with the array.array() solution to store collected data, hoping for the smallest possible overhead.
Thanks!



More information about the Python-list mailing list