rainwoodman / sharedmem

A different flavor of multiprocessing in Python
GNU General Public License v3.0
81 stars 9 forks source link

Initialise numpy array of unknown length and don't have append function #10

Open powercode007 opened 7 years ago

powercode007 commented 7 years ago

Numpy array have append function. when i create using sharedmem isn't working.

what i want is a while with a condition which append current time in sharedmem numpy arrray. Any direction clue would be helpful. Thanx in advance

rainwoodman commented 7 years ago

If there is an upper bound of the number of entries in the array, then you can preallocate the shared array, and create another shared array that counts the number of used items.

Along these lines.

t = sharedmem.empty(upperbound, dtype='f8')
t_used = sharedmem.empty((,), dtype='i8')

t_used[...] = 0

Protected by a lock /critical section you can do

t[t_used] = new_value
t_used[...] += 1