简体   繁体   English

多处理帮助。 BrokenProcessPool 错误

[英]Multiprocessing Help. BrokenProcessPool Error

I'm trying to learn the basics of multi-processing in python, and found the following example online which I wanted to practice with.我正在尝试学习 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())

Fairly simple, I know.相当简单,我知道。 However, for some reason when I try and run this, I get the following error.但是,由于某种原因,当我尝试运行它时,出现以下错误。

Traceback (most recent call last):回溯(最近一次调用最后一次):

File "", line 19, in print(f1.result())文件“”,第 19 行,在 print(f1.result()) 中

File "C:\\Anaconda3\\lib\\concurrent\\futures_base.py", line 432, in result return self.__get_result()文件“C:\\Anaconda3\\lib\\concurrent\\futures_base.py”,第 432 行,结果返回 self.__get_result()

File "C:\\Anaconda3\\lib\\concurrent\\futures_base.py", line 384, in __get_result raise self._exception文件“C:\\Anaconda3\\lib\\concurrent\\futures_base.py”,第 384 行,在 __get_result 中引发 self._exception

BrokenProcessPool: A process in the process pool was terminated abruptly while the future was running or pending. BrokenProcessPool:进程池中的进程在未来运行或挂起时突然终止。

Any idea what is causing this?知道是什么原因造成的吗?

You might want to check if the future is done already:您可能想检查未来是否已经完成:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM