Improve Py_mod_multiple_interpreters and Py_mod_gil Usability
未关闭
还没有人认领这个 Issue。
3.15
interpreter-core
topic-C-API
topic-free-threading
topic-subinterpreters
type-feature
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
Feature or enhancement
Proposal:
Here are some deficiencies:
- the slot name "Py_mod_multiple_interpreters" is a bit long
- the "Py_MOD_MULTIPLE_INTERPRETERS_*" slot value names are a bit long
- the slot name "Py_mod_gil" is overly coupled to the GIL (it's really about thread safety)
- the difference between
Py_MOD_MULTIPLE_INTERPRETERS_SUPPORTEDandPy_MOD_PER_INTERPRETER_GIL_SUPPORTEDis unclear Py_MOD_PER_INTERPRETER_GIL_SUPPORTEDapplies to the vast majority of extensions and should be the defaultPy_mod_gildoesn't have an option that explicitly covers the case where an external dependency is not thread-safe- currently
Py_MOD_MULTIPLE_INTERPRETERS_SUPPORTEDimplies an external dependency is not thread-safe and/or isolated to each interpreter; it should be the other way around (and be a synonym forPy_MOD_PER_INTERPRETER_GIL_SUPPORTED), which would introduce a need for aPy_MOD_PER_INTERPRETER_GIL_NOT_SUPPORTED
We could take a simple approach, working with the existing slots:
- (maybe) shorten the names
- add
Py_MOD_PER_INTERPRETER_GIL_NOT_SUPPORTED - add something like
Py_MOD_GIL_USED_FOR_EXTERNAL
I think we could do better, by replacing the existing slots with new ones that focus explicitly on what we care about:
- new module def slot:
Py_mod_isolationPy_MOD_NOT_ISOLATED- the module has process-global state and/or objects (e.g. static types)Py_MOD_ISOLATED(default) - the module's state/objects have been isolated to the module (i.e interpreter)
- new module def slot:
Py_mod_threadsafePy_MOD_NOT_THREADSAFE(default) - the module's own state/code is not thread-safePy_MOD_THREADSAFE- the module's state/code are thread-safe; external dependencies are covered byPy_mod_external_libs
- new module def slot:
Py_mod_external_libsPy_MOD_EXTERN_NOT_THREADSAFE- at least one external dependency is not thread-safe (may be used without the GIL held)Py_MOD_EXTERN_NOT_ISOLATED- at least one external dependency is not isolated to the module object (i.e. interpreter)Py_MOD_EXTERN_ISOLATED(default) - all external dependencies are isolated and using them is thread-safe
- for
Py_mod_isolationandPy_mod_threadsafe, external dependencies are covered byPy_mod_external_libs - deprecate
Py_mod_multiple_interpretersslot - deprecate
Py_mod_gilslot
Regarding the defaults, for Py_mod_isolation, multi-phase init implies isolation (per PEP 489). For Py_mod_external_libs, we assume that the vast majority of modules will not have problematic dependencies.
Equivalents to current usage:
| Py_mod_threadsafe | Py_mod_external_libs | Py_mod_gil | |
|---|---|---|---|
| Py_MOD_NOT_THREADSAFE | * | Py_MOD_GIL_USED | |
| Py_MOD_THREADSAFE | Py_MOD_EXTERNAL_NOT_THREADSAFE | Py_MOD_GIL_USED | |
| Py_MOD_THREADSAFE | Py_MOD_EXTERNAL_NOT_ISOLATED | Py_MOD_GIL_NOT_USED | |
| Py_MOD_THREADSAFE | Py_MOD_EXTERNAL_ISOLATED | Py_MOD_GIL_NOT_USED |
| Py_mod_isolation | Py_mod_external_libs | Py_mod_multiple_interpreters | |
|---|---|---|---|
| Py_MOD_NOT_ISOLATED | * | Py_MOD_MULTIPLE_INTERPRETERS_NOT_SUPPORTED | |
| Py_MOD_ISOLATED | Py_MOD_EXTERNAL_NOT_THREADSAFE | Py_MOD_MULTIPLE_INTERPRETERS_SUPPORTED | |
| Py_MOD_ISOLATED | Py_MOD_EXTERNAL_NOT_ISOLATED | Py_MOD_MULTIPLE_INTERPRETERS_SUPPORTED | |
| Py_MOD_ISOLATED | Py_MOD_EXTERNAL_ISOLATED | Py_MOD_PER_INTERPRETER_GIL_SUPPORTED |
CC @encukou
Has this already been discussed elsewhere?
No response given
Links to previous discussion of this feature:
No response
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
该 issue 未指定源文件或测试;首先定位现有的 Py_mod_multiple_interpreters 和 Py_mod_gil slot 定义,并检查它们当前的行为。先与维护者确定提议的 slot 名称、默认值和 deprecations;完成这项工作需要达成一致的设计,并提供相应的实现和测试。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- backend
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 需要澄清
- 新手友好度
- 25/100