Python ProcessPoolExecutor由于调用unpickle映像而陷入死锁

Python ProcessPoolExecutor由于调用unpickle映像而陷入死锁,python,image,image-processing,machine-learning,deadlock,Python,Image,Image Processing,Machine Learning,Deadlock,嗨,我在做图像处理 我正在使用ProcessPoolExecutor来加快图像数据处理速度,它可以正常工作,直到找到一个未勾选的图像(但我不确定这是否是真正的问题,我在谷歌上搜索了好几个小时……) 它引起了 打字错误 。。。永远陷入僵局 没有ProcessPoolExecutor,代码运行良好,因此我认为我的代码没有任何问题,只有ProcessPoolExecutor 所以我的问题是,“有没有办法避免ProcessPoolExecutor陷入死锁状态?” 我的代码如下: def image_re

嗨,我在做图像处理

我正在使用
ProcessPoolExecutor
来加快图像数据处理速度,它可以正常工作,直到找到一个未勾选的图像(但我不确定这是否是真正的问题,我在谷歌上搜索了好几个小时……)

它引起了

打字错误

。。。永远陷入僵局

没有ProcessPoolExecutor,代码运行良好,因此我认为我的代码没有任何问题,只有ProcessPoolExecutor

所以我的问题是,“有没有办法避免ProcessPoolExecutor陷入死锁状态?”

我的代码如下:

def image_resize(filename):
    image_size = 50
    img = Image.open(filename)
    img = img.convert("RGB")
    img = img.resize((image_size, image_size))
    return img

def main():
    for idx, cat in enumerate(categories):
        image_dir = root_dir + "/" + cat
        files = glob.glob(image_dir + "/01" + "/*.jpg")

        with concurrent.futures.ProcessPoolExecutor() as executor:
            for f, img in zip(files, executor.map(image_resize, files, timeout=3, chunksize=1)):

                data = np.asarray(img)
                X.append(data)
                Y.append(idx)

if __name__ == '__main__':
    main()
    X = np.array(X)
    Y = np.array(Y)
    X_train, X_test, y_train, y_test = train_test_split(X, Y)
    xy = (X_train, X_test, y_train, y_test)
    np.save("./food3.npy", xy)
    print("ok,", len(Y))
错误消息:

Exception in thread Thread-1:
Traceback (most recent call last):
  File "C:\Programs\Python\Python35\lib\threading.py", line 914, in _bootstrap_inner
    self.run()
  File "C:\Programs\Python\Python35\lib\threading.py", line 862, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Programs\Python\Python35\lib\concurrent\futures\process.py", line 273, in _queue_management_worker
    result_item = reader.recv()
  File "C:\Programs\Python\Python35\lib\multiprocessing\connection.py", line 251, in recv
    return ForkingPickler.loads(buf.getbuffer())
TypeError: __new__() missing 2 required positional arguments: 'lang' and 'tkey'

你可能受这个枕头的影响

目前我看到的唯一解决方法是在返回
image\u resize
之前,尝试在
img
中对对象进行pickle处理。如果失败,只需返回其他内容(
False
None
)或在函数本身中引发异常


该池更加健壮,可以透明地处理问题。

如果需要帮助,请修复缩进。Python中的缩进对于正确解释代码至关重要。我们不是计算机,但我们不想把时间浪费在不可读的代码上。奇怪的是,这个bug已经存在这么久了,这个类只需要一个方法。作为解决方法,monkeypatching似乎可以工作:
PngImagePlugin.iTXt.\uuu getnewargs\uuuu=lambda self:(str(self)、self.lang、self.tkey)
,但这取决于每个子流程中必须采用的多处理启动模式。这并不简单,因为它们需要支持多个python和pickle版本,而不考虑不同的多处理启动方法。测试需要编写等。。所以我想他们还有其他的优先事项。。