python - 多处理帮助。 BrokenProcessPool 错误

我正在尝试学习 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())

https://stackoverflow.com/questions/59581158/

相关文章:

javascript - CSS 不透明度过渡不适用于 Safari

asp.net-core - 如何关联给定电路或 "session"的 Blazor 事件

java - Slf4j,logback - 从 json 中删除 mdc 标签

python - PyAutoGUI,停止命令

typescript - npm 如何发布 typescript 接口(interface)定义

flutter - showDialog 后键盘关闭

amazon-web-services - 使用 Amazon API Gateway 和 Lamb

c++ - 如何检测非事件 Win32 应用程序中的最小化?

azure - 如何为使用一些不同参数的模板使用一个参数文件? (在 DevOps Pipeline

c# - 在 Blazor 应用程序中使用 Azure Active Directory 时如何在