I’d like to share several numpy arrays between different child processes with python’s multiprocessing module. I’d like the arrays to be separately lockable, and I’d like the number of arrays to be dynamically determined at runtime. Is this possible?
In this answer, J.F. Sebastian lays out a nice way to use python’s numpy arrays in shared memory while multiprocessing. The array is lockable, which is what I want. I would like to do something very similar, except with a variable number of shared arrays. The number of arrays would be determined at runtime. His example code is very clear and does almost exactly what I want, but I’m unclear how to declare a variable number of such arrays without giving each one of them a hard-coded name like shared_arr_1, shared_arr_2, et cetera. What’s the right way to do this?
Turns out this was easier than I thought! Following J.F. Sebastian’s encouragement, here’s my crack at an answer:
Background: This is the skeleton of a data-acquisition pipeline. I want to acquire data at a very high rate, process it for on-screen display, and save it to disk. I don’t ever want display rate or disk rate to limit acquisition, which is why I think using separate child processes in individual processing loops is appropriate.
Here’s typical output of the dummy program:
It seems to do what I want: the data gets processed for display and saved to disk without interfering with the acquisition rate.