每个进程都有一套自己的内存, 所以在子进程中创建的list或者dict没法直接传回子进程, 只能用多进程模块提供的队列或者管道。
python多进程获取返回值:
pool = mp.Pool(processes=8) for j in range(0, n): res = pool.apply_async(MICS, args=( LUCC2[j * x_slice:j * x_slice + x_slice, :], NPP2[j * x_slice:j * x_slice + x_slice, :], TMP2[j * x_slice:j * x_slice + x_slice, :], f_clay2[j * x_slice:j * x_slice + x_slice, :], LUCC_land2[j * x_slice:j * x_slice + x_slice, :], j)) res1.append(res) pool.close() pool.join() res2 = [i.get() for i in res1]