使用 concurrent.futures.ProcessPoolExecutor() 时出现 BrokenProcessPool 错误消息的原因?
Reaon of BrokenProcessPool error message while using concurrent.futures.ProcessPoolExecutor()?
我正在尝试 运行 在 Jupyter notebook 上执行以下代码(使用 Python 3.7.5):
import time
import concurrent.futures
start = time.perf_counter()
def do_something(seconds):
print(f'sleeping for {seconds} seconds')
time.sleep(seconds)
return 'done sleeping'
with concurrent.futures.ProcessPoolExecutor() as executor:
results = [executor.submit(do_something, 1) for _ in range(10)]
for f in concurrent.futures.as_completed(results):
print(f.result())
finish = time.perf_counter()
print(f'finished in {round(finish-start,9)} seconds')
但是,解释器显示一条错误消息:
BrokenProcessPool: A process in the process pool was terminated abruptly while the future was running or pending.
我正在通过 YouTube 教程学习多处理,该代码在该教程中运行良好。我没有找到任何讨论此错误的网页。
代码正确;但是它在 Jupyter 中不起作用。
根据 docs:
的预期行为
The main module must be importable by worker subprocesses. This
means that ProcessPoolExecutor will not work in the interactive
interpreter.
我正在尝试 运行 在 Jupyter notebook 上执行以下代码(使用 Python 3.7.5):
import time
import concurrent.futures
start = time.perf_counter()
def do_something(seconds):
print(f'sleeping for {seconds} seconds')
time.sleep(seconds)
return 'done sleeping'
with concurrent.futures.ProcessPoolExecutor() as executor:
results = [executor.submit(do_something, 1) for _ in range(10)]
for f in concurrent.futures.as_completed(results):
print(f.result())
finish = time.perf_counter()
print(f'finished in {round(finish-start,9)} seconds')
但是,解释器显示一条错误消息:
BrokenProcessPool: A process in the process pool was terminated abruptly while the future was running or pending.
我正在通过 YouTube 教程学习多处理,该代码在该教程中运行良好。我没有找到任何讨论此错误的网页。
代码正确;但是它在 Jupyter 中不起作用。
根据 docs:
The main module must be importable by worker subprocesses. This means that ProcessPoolExecutor will not work in the interactive interpreter.