I want to use an array for shared memory. The problem is that the program is structured so that the child processes are spawned before I know the size of the shared array. If I send a message to expand the array, nothing happens, and if I try to send the shared array itself, I get an error message. Below is a small script to demonstrate my problem.
import multiprocessing as mp import numpy as np def f(a,pipe): while True: message, data = pipe.recv() if message == 'extend': a = np.zeros(data) print a elif message == 'exit': break if __name__ == '__main__': unshared_arr = np.zeros(1) a = mp.Array('d', unshared_arr) p1,p2 = mp.Pipe() p = mp.Process(target=f, args=(a,p2)) p.start() p1.send(('extend', 10)) p1.send(('exit', None)) p.join() b = np.frombuffer(a.get_obj())
Chicony Dec 08 '16 at 10:59 2016-12-08 10:59
source share