|
我为了共享array,把他的data buffer拿出来给了子进程。
shared_batch = np.empty([32,3,224,224], dtype=np.float32)
buf_ptr = shared_batch.ctypes.data
print 'init address ', buf_ptr
processes = [Process(target=sub_process,args=(shared_batch.data) ) for i in range(4)]
然后子进程里
def read_images(shared_buffer):
with lock:
buf_ptr = buf.ctypes.data
print 'befrore set %d, %f'%(buf_ptr, buf[0])
buf = np.frombuffer(shared_buffer, dtype=np.float32, count=3*224*224, offset=0)
buf_ptr = buf.ctypes.data
print 'befrore set %d, %f'%(buf_ptr, buf[0])
buf[0] = 0.35
子进程结束后,到主进程去
print shared_batch[0]
死活不是0.35,一直是初始值。所有的地址buf_ptr,都是一模一样的。
|
|