Change RLock from factory function to actual type, remove dead Python RLock implementation
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 35.9k
- PR merge metrics
- PR metrics pending
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with Lib/threading.py and the _thread.RLock entry point, then review the linked PR discussions before making changes. Confirm the proposed alias and removal are compatible with the supported platforms and existing threading behavior; done means the dead _RLock implementation is removed and threading.RLock directly refers to the C implementation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- operating-systems
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100