ProcessPoolExecutor executor manager thread crashes if task fails in some circumstances
未關閉
@gpshead 已經在處理了。
開始於 2026年7月3日。
3.13
3.14
stdlib
topic-multiprocessing
type-bug
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 35.9k
- PR 合併指標
- PR 指標待擷取
描述
Bug report
Bug description:
import time
from concurrent.futures import ProcessPoolExecutor
def fail():
time.sleep(1)
raise ValueError()
executor = ProcessPoolExecutor(max_workers=1, max_tasks_per_child=1)
try:
print(executor.submit(fail).exception() is not None)
finally:
executor.shutdown(wait=False)
If you run this, then the following is printed to the console:
Exception in thread Thread-1:
Traceback (most recent call last):
File "python3.11/threading.py", line 1045, in _bootstrap_inner
self.run()
File "python3.11/concurrent/futures/process.py", line 364, in run
executor._adjust_process_count()
File "python3.11/concurrent/futures/process.py", line 759, in _adjust_process_count
process_count = len(self._processes)
^^^^^^^^^^^^^^^^^^^^
TypeError: object of type 'NoneType' has no len()
If you change the code to using wait=True, or remove the max_tasks_per_child=1 option then the message is not printed.
Probably the fix is just to check if self.processes is None before accessing it at https://github.com/python/cpython/blob/main/Lib/concurrent/futures/process.py#L762
CPython versions tested on:
3.11
Operating systems tested on:
Linux
Linked PRs
- gh-152978
- gh-153363
- gh-154873
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
評估
這個 Issue 還沒有評估資料。