python - 多处理帮助。 BrokenProcessPool 错误

标签 python multiprocessing python-multiprocessing

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

相关文章:

python - 任何加速从磁盘读取数据并将其转换为 numpy 数组以供进一步处理的解决方案?

python - 结合输出多处理python

python - 多处理的queue.get()什么时候返回DONE?

python - Django 任务管理系统

python多处理根本不起作用

python - 如何判断 apply_async 函数是否已启动或它是否仍在 multiprocessing.Pool 队列中

python - 多处理模块出现死锁

jquery - 无法在 Bootstrap 中提交我的模态表单

C++ 中的 Python 风格字符串替换

python - 如何为 python 客户端提供来自 python 服务器的端口号