Change RLock from factory function to actual type, remove dead Python RLock implementation
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 77.2k
- Forks
- 35.9k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
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) inLib/threading.pyis dead code and should be removed. - There's no longer any point in making
threading.RLocka factory function. (Was there ever a point?)threading.RLockshould 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
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit Lib/threading.py und dem Einstiegspunkt _thread.RLock und prüfe anschließend die verknüpften PR-Diskussionen, bevor du Änderungen vornimmst. Bestätige, dass der vorgeschlagene Alias und die Entfernung mit den unterstützten Plattformen und dem bestehenden threading-Verhalten kompatibel sind; fertig ist die Änderung, wenn die nicht mehr verwendete _RLock-Implementierung entfernt wurde und threading.RLock direkt auf die C-Implementierung verweist.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- operating-systems
- Issue-Typ
- Feature
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 25/100