python / python/cpython

Change RLock from factory function to actual type, remove dead Python RLock implementation

オープン
#141,460 コメント 5 件 リアクション 2 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

stdlib type-feature
主要言語
Python
スター
77.2k
フォーク
35.9k
PR マージ指標
PR 指標を取得中

説明

Feature or enhancement

Proposal:

Currently in CPython threading.RLock is a factory function that returns a new RLock instance. It either returns an instance of _CRLock, if it's defined, otherwise it returns an instance of _PyRLock. I'm kidding--in practice, it never returns _PyRLock. You'd have to do something silly (threading._CRLock = None) in order to get it to return an instance of _PyRLock, because these days _CRLock is always defined.

I haven't gone reading through old versions / git blame / etc, but my guess is that CPython used to support platforms that didn't have a native RLock, or the C implementation of RLock was unsuitable for some reason on some platforms. Here in 2025 I find the C implementation of RLock is unguarded by any #if / #ifdef statement. All platforms currently supported by CPython must support threading, the C version of RLock (_thread.RLock) is always defined, and the threading.RLock factory function always returns an instance of that object (unless you do something silly).

Assuming I'm right about all that:

  • The Python implementation of RLock (class _RLock) in Lib/threading.py is dead code and should be removed.
  • There's no longer any point in making threading.RLock a factory function. (Was there ever a point?) threading.RLock should simply be an alias for the RLock implementation in C (_thread.RLock).
Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Linked PRs
  • gh-141462
  • gh-142977

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

Lib/threading.py と _thread.RLock のエントリーポイントから始め、変更を加える前にリンクされた PR の議論を確認してください。提案されたエイリアスと削除が、サポート対象プラットフォームおよび既存の threading の動作と互換性があることを確認してください。_RLock の不要な実装が削除され、threading.RLock が C 実装を直接参照する状態になれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
operating-systems
issue の種類
機能追加
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。