多处理帮助.BrokenProcessPool 错误 [英] Multiprocessing Help. BrokenProcessPool Error
问题描述
我正在尝试学习 Python 中多处理的基础知识,并在网上找到了以下我想练习的示例.
I'm trying to learn the basics of multi-processing in python, and found the following example online which I wanted to practice with.
import concurrent.futures
import time
def do_something(seconds):
print(f' Sleeping {seconds} seconds')
time.sleep(seconds)
return f'Done Sleeping {seconds}'
with concurrent.futures.ProcessPoolExecutor() as executor:
f1 = executor.submit(do_something, 1)
print(f1.result())
很简单,我知道.但是,由于某种原因,当我尝试运行它时,出现以下错误.
Fairly simple, I know. However, for some reason when I try and run this, I get the following error.
回溯(最近一次调用最后一次):
Traceback (most recent call last):
文件",第 19 行,在打印(f1.result())
File "", line 19, in print(f1.result())
文件C:\Anaconda3\lib\concurrent\futures_base.py",第 432 行,在结果返回 self.__get_result()
File "C:\Anaconda3\lib\concurrent\futures_base.py", line 432, in result return self.__get_result()
文件C:\Anaconda3\lib\concurrent\futures_base.py",第 384 行,在__get_result提出 self._exception
File "C:\Anaconda3\lib\concurrent\futures_base.py", line 384, in __get_result raise self._exception
BrokenProcessPool:进程池中的一个进程被终止在未来运行或待定时突然出现.
BrokenProcessPool: A process in the process pool was terminated abruptly while the future was running or pending.
知道是什么原因造成的吗?
Any idea what is causing this?
推荐答案
你可能想检查未来是否已经完成:
You might want to check if the future is done already:
if f1.done():
print(f1.result())
这篇关于多处理帮助.BrokenProcessPool 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!