我正在尝试使用Pool和许多工人来处理一些阵列。当我使用较大的数组时,我使用共享内存,该共享内存稍后会在调用的函数中转换为numpy数组:
shared_arr = Array(ctypes.c_ulong, size[0] * size[1])
img = tonumpyarray(shared_arr, size)
shared_arr_l = Array(ctypes.c_ulong, size[0] * size[1])
labimg = tonumpyarray(shared_arr_l, size)
池功能为:
with closing(Pool(initializer=init, initargs=(shared_arr, shared_arr_l), processes=n_cores)) as p:
p.starmap_async(classific, [(p, size) for p in props1])
p.join()
它适用于小数据,但对于大数据,我为每个工作人员得到一个AssertionError:
Process SpawnPoolWorker-1:
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\Lib\multiprocessing\process.py", line 258, in _bootstrap
self.run()
File "C:\ProgramData\Anaconda3\Lib\multiprocessing\process.py", line 93, in run
self._target(*self._args, **self._kwargs)
File "C:\ProgramData\Anaconda3\Lib\multiprocessing\pool.py", line 108, in worker
task = get()
File "C:\ProgramData\Anaconda3\Lib\multiprocessing\queues.py", line 335, in get
res = self._reader.recv_bytes()
File "C:\ProgramData\Anaconda3\Lib\multiprocessing\connection.py", line 216, in recv_bytes
buf = self._recv_bytes(maxlength)
File "C:\ProgramData\Anaconda3\Lib\multiprocessing\connection.py", line 318, in _recv_bytes
return self._get_more_data(ov, maxsize)
File "C:\ProgramData\Anaconda3\Lib\multiprocessing\connection.py", line 337, in _get_more_data
assert left > 0
AssertionError
这是内存问题吗? RAM不会有问题-计算机具有128 GB,而两个阵列小于2 GB并存储在共享内存中。 我试图解决它,但我迷路了。 任何帮助将不胜感激。