`concurrent.futures.Executor.map` with `buffersize` should yield from buffer and raise after executor shutdown
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
Bug report
Bug description:
As pointed by @salomvary in this discussion, the behavior of concurrent.futures.Executor.map with buffersize is misleading when iterating after the executor's shutdown. There is 2 cases:
- Create the generator, shut down the executor, start iterating:
with ThreadPoolExecutor(1) as executor:
iterator = executor.map(str, range(8), buffersize=2)
# start iterating after the shutdown
assert next(iterator) == "0"
assert next(iterator) == "1"
# raises StopIteration
next(iterator)
In this scenario the elements from the buffer are yielded, then the iteration is stopped.
- Create the generator, start the iteration, shut down the executor, continue the iteration
with ThreadPoolExecutor(1) as executor:
iterator = executor.map(str, range(8), buffersize=2)
# start iterating before the shutdown
assert next(iterator) == "0"
# raises "RuntimeError: cannot schedule new futures after shutdown"
next(iterator)
In this scenario a RuntimeError is raised by the first post-shutdown next, leaving not-yet-yielded results in the buffer.
I would vote for a mix of both: yield from the buffer and then raise the exception.
(the fix would be a dozen rows)
CPython versions tested on:
3.14, 3.15
Operating systems tested on:
macOS, Linux, Windows
Linked PRs
- gh-146395
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
使用 concurrent.futures.Executor.map 及其 buffersize 参数重现 issue 中的两种 shutdown 场景。检查 Executor.map 的迭代路径,然后补充对在 shutdown 后异常发生之前 yield 已缓冲结果的覆盖,并验证现有示例的行为符合描述。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- backend
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 30/100