首页 > 解决方案 > Python ProcessPoolExecutor.map 对于大型结果数组失败

问题描述

我在生成并返回两个 numpy 数组的函数上使用 ProcessPoolExecutor.map。这些数组的大小取决于函数的输入参数。

with concurrent.futures.ProcessPoolExecutor() as executor:
    results = executor.map(self.compute_slice, arguments)

当我的结果数组为 (1296,1296)、float32 时,我得到了预期的输出。但是,当我将分辨率加倍到 (2574, 2574) 时,我收到一条错误消息:

Traceback (most recent call last):
  File "/usr/lib64/python3.6/multiprocessing/queues.py", line 240, in _feed
    send_bytes(obj)
  File "/usr/lib64/python3.6/multiprocessing/connection.py", line 204, in send_bytes
    self._send_bytes(m[offset:offset + size])
  File "/usr/lib64/python3.6/multiprocessing/connection.py", line 397, in _send_bytes
    header = struct.pack("!i", n)
struct.error: 'i' format requires -2147483648 <= number <= 2147483647

但是,我需要处理最大为 (10000, 10000) 的数组。我确定我有足够的可用内存。谷歌搜索这个错误什么也没告诉我,它似乎非常通用并且出现在各种上下文中。

标签: pythonnumpyconcurrent.futures

解决方案


推荐阅读