Warn about future default of `thread_inherit_context=1`.
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
Feature or enhancement
Proposal:
For background discussion, see this Discourse thread.
The current behavior of threading.Thread not inheriting context variables from the starting thread is considered a bug. It is an oversight in the initial implementation of contextvars (confirmed in discussion with Yury). In a future Python release (version to be decided) we want to change that to happen by default (i.e. make the thread_inherit_context config flag default to true) . For the free-threaded build, thread_inherit_context already defaults to true, since that's required for sensible thread-safe behavior from the warnings module.
The reason to change is that libraries want to replace global state with context-local state (typically to be thread-safe or to be asyncio compatible). It is surprising and inconvenient if this context-local state is "lost" when a new thread is started. The Discourse thread has some examples of real-world experience with this.
This is an incompatible change and so we want to warn about this if we detect code that might be affected. If the warning first appears in Python 3.15, PEP 387 requires it to remain in Python 3.15 and 3.16; the default may change in Python 3.17 at the earliest.
Has this already been discussed elsewhere?
I have already discussed this feature proposal on Discourse
Links to previous discussion of this feature:
Linked PRs
- gh-154558
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
threading.Thread エントリーポイントと thread_inherit_context 構成フラグから始め、リンクされている PR gh-154558 と参照されている Discourse の議論を確認します。完了条件は、デフォルトをまだ変更せずに、影響を受けるコードに将来のデフォルト変更について警告することです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- backend
- issue の種類
- 機能追加
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 25/100