Closed
Description
Bug report
Bug description:
import threading
r = threading.RLock()
print(f"{r = }")
output is:
r = <unlocked _thread.RLock object owner=0 count=1 at 0x105a98720>
The threading.RLock.__repr__
seems to me erronous because when a threading.RLock
is just created, its count
attribute should be 0.
This error occurs only with the _thread
module.
I can submit a PR.
CPython versions tested on:
CPython main branch
Operating systems tested on:
macOS
Activity
picnixz commentedon May 20, 2025
Yes, it's because of:
which doesn't check whether the lock is unlocked or not.
YvesDup commentedon May 20, 2025
Yes, we have to check the lock state as in the
rlock_recursion_count
function from the_thread
module.__repr__
value ofthreading.RLock
from_thread
module, when just created #134389vstinner commentedon May 20, 2025
It's a regression introduced in Python 3.14 by commit 67f6e08. cc @kumaraditya303
vstinner commentedon May 20, 2025
Python 3.13 is not affected:
gh-134322: Fix `repr(threading.RLock)` (#134389)
pythongh-134322: Fix `repr(threading.RLock)` (pythonGH-134389)
repr(threading.RLock)
(GH-134389) #134528[3.14] gh-134322: Fix `repr(threading.RLock)` (GH-134389) (#134528)
pythongh-134322: Fix `repr(threading.RLock)` (python#134389)