- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
嗨,我正在研究图像处理
我正在使用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
对象。如果失败,您只需返回其他内容(False
、None
)或在函数本身内引发异常。
pebble池更加强大,它可能会为您透明地处理问题。
关于Python ProcessPoolExecutor 由于调用 unpickle image 而陷入死锁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49168542/
我有类似下面的代码: ... id: myComponent signal updateState() property variant modelList: [] Repeater { mo
我正在处理一些我无法展示的私有(private)代码,但我已经制作了一些示例代码来描述我的问题: 主.c: #include #include #include #include typede
这个问题在这里已经有了答案: 关闭10 年前。 Possible Duplicate: what are the differences in die() and exit() in PHP? 我想
在编写 Perl 模块时,在模块内部使用 croak/die 是一个好习惯吗? 毕竟,如果调用者不使用 eval block ,模块可能会使调用它的程序崩溃。 在这些情况下,最佳做法是什么? 最佳答案
我有一些搜索线程正在存储结果。我知道当线程启动时,JVM native 代码会代理在操作系统上创建新 native 线程的请求。这需要 JVM 之外的一些内存。当线程终止并且我保留对它的引用并将其用作
我刚刚花了很多时间调试一个我追溯到 wantarray() 的问题。 .我已将其提炼为这个测试用例。 (忽略 $! 在这种情况下不会有任何有用信息的事实)。我想知道为什么wantarray在第二个示例
我看到一些代码是这样做的: if(something){ echo 'exit from program'; die; } ...more code 和其他只使用 die 的人: if
我正在尝试将此表格用于: 如果任何 $_POST 变量等于任何其他 $_POST 变量抛出错误。 如果只有几个,那不是问题,但我有大约 20 个左右所以如果我想这样做,我将不得不像这样 但这
每次我运行: hadoop dfsadmin -report 我得到以下输出: Configured Capacity: 0 (0 KB) Present Capacity: 0 (0 KB) DFS
我是一名优秀的程序员,十分优秀!