Skip to content

Commit c06df43

Browse files
committed
Iniial commit
1 parent 28625d4 commit c06df43

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

Lib/test/lock_tests.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,11 @@ class RLockTests(BaseLockTests):
337337
"""
338338
Tests for recursive locks.
339339
"""
340+
def test_locked_repr(self):
341+
super().test_locked_repr()
342+
lock = self.locktype()
343+
self.assertIn("count=0", repr(lock))
344+
340345
def test_reacquire(self):
341346
lock = self.locktype()
342347
lock.acquire()

Modules/_threadmodule.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1219,7 +1219,8 @@ rlock_repr(PyObject *op)
12191219
{
12201220
rlockobject *self = rlockobject_CAST(op);
12211221
PyThread_ident_t owner = self->lock.thread;
1222-
size_t count = self->lock.level + 1;
1222+
size_t count = _PyRecursiveMutex_IsLockedByCurrentThread(&self->lock) ?
1223+
self->lock.level + 1 : 0;
12231224
return PyUnicode_FromFormat(
12241225
"<%s %s object owner=%" PY_FORMAT_THREAD_IDENT_T " count=%zu at %p>",
12251226
owner ? "locked" : "unlocked",

0 commit comments

Comments
 (0)