gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 09:07:14 25 4
gpt4 key购买 nike

嗨,我正在研究图像处理

我正在使用ProcessPoolExecutor来使图像数据处理更快,它工作正常,直到它似乎找到未腌制的图像(但我不确定这是否是真正的问题,我做了一些谷歌搜索许多小时..)

它提高了...

TypeError

...并永远陷入僵局。

代码在没有 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'

最佳答案

您可能受到这个枕头的影响bug .

我目前看到的唯一解决方法是在返回之前尝试在 image_resize 中腌制 img 对象。如果失败,您只需返回其他内容(FalseNone)或在函数本身内引发异常。

pebble池更加强大,它可能会为您透明地处理问题。

关于Python ProcessPoolExecutor 由于调用 unpickle image 而陷入死锁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49168542/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com