简体   繁体   中英

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.

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

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.

Any idea what is causing this?

You might want to check if the future is done already:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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