Add a typed exception for concurrent.futures executor shutdown
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
Proposal:
concurrent.futures.Executor.submit() implementations currently raise a generic RuntimeError when work is submitted after executor shutdown. For example, ThreadPoolExecutor.submit() raises one of these messages:
RuntimeError("cannot schedule new futures after shutdown")
RuntimeError("cannot schedule new futures after interpreter shutdown")
This makes it difficult for callers to distinguish expected executor lifecycle failures from unrelated RuntimeErrors without matching exception message strings:
try:
future = executor.submit(fn)
except RuntimeError as exc:
if str(exc) in {
"cannot schedule new futures after shutdown",
"cannot schedule new futures after interpreter shutdown",
}:
handle_executor_shutdown(exc)
else:
raise
It would be useful to expose a typed exception for this condition, for example:
class ExecutorShutdownError(RuntimeError):
pass
Then executor implementations could raise ExecutorShutdownError for explicit shutdown and interpreter-shutdown submission failures. Because it would subclass RuntimeError, existing callers catching RuntimeError would remain compatible, while callers that need precise handling could avoid brittle string matching:
try:
future = executor.submit(fn)
except concurrent.futures.ExecutorShutdownError:
handle_executor_shutdown()
This would mirror the existing benefit of typed executor failures such as BrokenExecutor, where callers can distinguish executor state from arbitrary runtime failures without inspecting exception text.
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
None. I searched existing CPython issues for ExecutorShutdownError, cannot schedule new futures after shutdown, cannot schedule new futures after interpreter shutdown, and related concurrent.futures RuntimeError shutdown exception type wording. I found issues about shutdown behavior itself, but not this typed-exception API request.
Linked PRs
- gh-153003
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先阅读 concurrent.futures.Executor.submit() 的实现以及现有的 BrokenExecutor API。检查链接的 PR gh-153003 及其相关测试;完成标准是:关闭期间的提交会暴露专用异常,同时保持与 RuntimeError 的兼容性,并覆盖显式关闭和解释器关闭的情况。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- backend-api-design
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100