gpt4 book ai didi

python - 多处理帮助。 BrokenProcessPool 错误

转载 作者:行者123 更新时间:2023-12-05 08:06:39 25 4
gpt4 key购买 nike

我正在尝试学习 python 中多处理的基础知识,并在网上找到了以下我想练习的示例。

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())

很简单,我知道。但是,出于某种原因,当我尝试运行它时,出现以下错误。

Traceback (most recent call last):

File "", line 19, in print(f1.result())

File "C:\Anaconda3\lib\concurrent\futures_base.py", line 432, in result return self.__get_result()

File "C:\Anaconda3\lib\concurrent\futures_base.py", line 384, in __get_result raise self._exception

BrokenProcessPool: A process in the process pool was terminated abruptly while the future was running or pending.

知道是什么原因造成的吗?

最佳答案

您可能想检查 future 是否已经完成:

if f1.done():
print(f1.result())

关于python - 多处理帮助。 BrokenProcessPool 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59581158/

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