selectors' closing behaviors completely inconsistent across selector types
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 30/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- python
调研方向
从 selectors.py 开始,比较 SelectSelector、PollSelector 和 EpollSelector,重点关注 close()、select()、fileno() 以及 closed 的行为。审查提议的跨线程唤醒和关闭后的语义,然后为每种 selector 类型添加覆盖,并验证已关闭的 selector 会引发 OSError,且阻塞的 select 调用会按指定方式返回。
由索引模型根据 Issue 内容生成。
描述
Several behaviors in selectors differ across implementations in major ways.
- What happens when a selector is selecting and is closed from a different thread?
- What happens when a selector is closed and
selectis called thereafter? - What error (if any) is raised if a selector cannot be used after close.
While individual select implementations can exhibit selector-type-specific behaviors, selectors provides a high-level abstraction that should behave in a consistent fashion.
Examples of inconsistent behaviors (select-after-close):
Python 3.10.4 (main, Mar 28 2022, 17:39:22) [GCC 11.2.1 20220127 (Red Hat 11.2.1-9)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import selectors
>>> s = selectors.SelectSelector()
>>> s.close()
>>> s.select()
^CTraceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/arcivanov/.pyenv/versions/3.10.4/lib/python3.10/selectors.py", line 324, in select
r, w, _ = self._select(self._readers, self._writers, [], timeout)
KeyboardInterrupt
>>> s = selectors.PollSelector()
>>> s.close()
>>> s.select()
^CTraceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/arcivanov/.pyenv/versions/3.10.4/lib/python3.10/selectors.py", line 416, in select
fd_event_list = self._selector.poll(timeout)
KeyboardInterrupt
>>> s = selectors.EpollSelector()
>>> s.close()
>>> s.select()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/arcivanov/.pyenv/versions/3.10.4/lib/python3.10/selectors.py", line 469, in select
fd_event_list = self._selector.poll(timeout, max_ev)
ValueError: I/O operation on closed epoll object
Proposal:
- Closing a selector (from a different thread) while it is blocked in a select will always result in select returning immediately with no ready keys. This indicates
EOFiftimeout=Noneor is indistinguishable from timeout otherwise. See [4]. - All selectors will have a
fileno()regardless of implementation. - In all cases where selector is call-based (
select/poll) a sentinel file (os.pipe) will be used as afileno()and never returned in the ready list. - Selecting on a closed selector will result in an
OSErrorirrespective of the underlying implementation. - Analogous to
fileobject,closedproperty returnsTruewhen selector is closed.
In cases when a selector implementation is not backed by a file-based object, this will result in 2 more file handles used per selector created (either a pipe or a socketpair).
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 36k
- 平均合并
- 1 天 9 小时
- 30 天内合并 PR
- 558
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
python/cpython 的其他 Issue
-
docs pending
难度 2/5 1-3 小时 新手友好度 78/100
-
stdlib type-feature
难度 2/5 1-3 小时 新手友好度 78/100
-
stdlib type-feature
难度 2/5 1-3 小时 新手友好度 72/100
-
build type-bug
难度 2/5 1-3 小时 新手友好度 76/100
-
stdlib topic-email type-feature
难度 2/5 1-3 小时 新手友好度 70/100
相似的 Issue
-
难度 1/5 1 小时以内 新手友好度 90/100
-
bug
难度 2/5 1-3 小时 新手友好度 86/100
zostera/django-bootstrap4#894 ·
-
难度 2/5 1-3 小时 新手友好度 78/100
use-agent-os/agent-os#3276 ·
-
难度 2/5 1-3 小时 新手友好度 88/100
zephyrproject-rtos/zephyr#119726 ·
-
area/auth bug comp/agent P3 platform/discord type/security
难度 2/5 1-3 小时 新手友好度 88/100
NousResearch/hermes-agent#117848 ·