Tracking issue for free-threading docs
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
Documentation
Summary
This is a tracking issue for the ongoing effort to improve thread safety documentation in CPython, covering both Python-level guarantees for built-in types and C API-level annotations for extension authors.
Completed work
Thread safety page and built-in type guarantees (gh-142518)
- Define free-threading related terms in the glossary
- gh-142519
- gh-144184
- gh-144716
- gh-145224
C API thread safety annotations (gh-145254)
- Define five annotation levels:
incompatible,compatible,distinct,shared,atomic - gh-145255
- Add thread safety levels reference section to
threadsafety.rst - Open python-docs-theme PR for rendering support
In progress (at the time of writing)
- gh-145225
- gh-145226
- gh-145911
- gh-145875
- gh-146109
Remaining work
stdlib type documentation
After built-in types, document thread-safety guarantees for stdlib types. Suggested priority:
-
collections.deque- widely used as a thread-safe queue substitute; people already assume it's safe; heavily used in asyncio internals -
iotypes (BufferedReader,BufferedWriter,TextIOWrapper) - file I/O is inherently concurrent in real programs; existing thread-safety notes are scattered and incomplete -
collections.defaultdict- the__missing__call introduces non-obvious concurrency questions (factory call is not atomic with insertion) -
collections.OrderedDict- has its own internal locking that differs from plain dict -
collections.Counter- commonly used for aggregation across threads -
array.array- mutable typed array, relevant for numeric/scientific code going parallel
Rationale: deque first because it's the most likely to be shared across threads today. io types next because concurrent file access is common and the current docs are inadequate. The collections types after that, ordered by usage frequency and concurrency risk. array.array last - niche usage, but mutable so still worth documenting.
Free-threading programming guide (new HOWTO)
A new Doc/howto/free-threading-guide.rst, alongside the existing two free-threading HOWTOs. The existing free-threading-python.rst stays focused on "what is free-threading / what changed." The new guide focuses on how to write correct concurrent code.
Topics to cover:
- Single operations vs. compound operations - why "thread-safe" doesn't mean "atomic"
- Common pitfalls: check-then-act, read-modify-write, iterating shared containers
- When and how to use
threading.Lockand other synchronization primitives - Practical patterns: queues,
concurrent.futures, thread-local storage - How to migrate existing threaded code that relied on the GIL
- Testing and debugging strategies (ThreadSanitizer, running under free-threaded builds)
- Summary reference table of built-in type thread safety (quick lookup, links to detailed per-type docs)
Cross-reference from free-threading-python.rst and from the per-type thread safety page.
asyncio free-threaded guide
Other documentation gaps
- Review and improve
queuemodule docs w.r.t. free-threaded builds - Address gh-84992
- Address gh-83556
C API annotations
- Annotate
PyObject_*APIs (creation, attribute access, comparison, etc.) - Annotate abstract layer APIs
-
PySequence_* -
PyMapping_* -
PyNumber_* -
PyIter_*
-
- Annotate reference counting APIs (
Py_INCREF,Py_DECREF,Py_NewRef, etc.) - Annotate GIL/critical-section APIs
- Annotate concrete type APIs
-
PyList_* -
PyDict_* -
PySet_* -
PyTuple_* -
PyUnicode_*
-
- Annotate buffer protocol APIs (
PyObject_GetBuffer,PyBuffer_Release, etc.) - Systematically work through remaining high-usage C API functions
Infrastructure improvements
- Coordinate with gh-116738 (audit all built-in modules for thread safety) - ensure doc annotations stay in sync with implementation fixes
- Add CI/linting to validate
threadsafety.datentries match actual function signatures - Consider generating per-module thread safety summary tables - especially in modules where it makes sense like
collections
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先从剩余工作中选择一个未勾选的、独立的项目,例如为一个 stdlib 类型编写文档,或创建 Doc/howto/free-threading-guide.rst。阅读相关的现有文档,包括 free-threading-python.rst 和 threadsafety.rst,然后完成所选的检查清单项目,并添加所要求的交叉引用或注释。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- documentation
- Issue 类型
- 文档
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 冷清
- 描述清晰度
- 需要澄清
- 新手友好度
- 25/100