Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Lib/test/lock_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,11 @@ class RLockTests(BaseLockTests):
"""
Tests for recursive locks.
"""
def test_locked_repr(self):
super().test_locked_repr()
lock = self.locktype()
self.assertIn("count=0", repr(lock))

def test_reacquire(self):
lock = self.locktype()
lock.acquire()
Expand Down
3 changes: 2 additions & 1 deletion Modules/_threadmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1219,7 +1219,8 @@ rlock_repr(PyObject *op)
{
rlockobject *self = rlockobject_CAST(op);
PyThread_ident_t owner = self->lock.thread;
size_t count = self->lock.level + 1;
size_t count = _PyRecursiveMutex_IsLockedByCurrentThread(&self->lock) ?
self->lock.level + 1 : 0;
return PyUnicode_FromFormat(
"<%s %s object owner=%" PY_FORMAT_THREAD_IDENT_T " count=%zu at %p>",
owner ? "locked" : "unlocked",
Expand Down
Loading