"""
Tests for recursive locks.
"""
+ def test_repr_count(self):
+ # see gh-134322: check that count values are correct:
+ # when a rlock is just created,
+ # in a second thread when rlock is acquired in the main thread.
+ lock = self.locktype()
+ self.assertIn("count=0", repr(lock))
+ self.assertIn("<unlocked", repr(lock))
+ lock.acquire()
+ lock.acquire()
+ self.assertIn("count=2", repr(lock))
+ self.assertIn("<locked", repr(lock))
+
+ result = []
+ def call_repr():
+ result.append(repr(lock))
+ with Bunch(call_repr, 1):
+ pass
+ self.assertIn("count=2", result[0])
+ self.assertIn("<locked", result[0])
+
def test_reacquire(self):
lock = self.locktype()
lock.acquire()
rlockobject *self = rlockobject_CAST(op);
PyThread_ident_t owner = self->lock.thread;
int locked = rlock_locked_impl(self);
- size_t count = self->lock.level + 1;
+ size_t count;
+ if (locked) {
+ count = self->lock.level + 1;
+ }
+ else {
+ count = 0;
+ }
return PyUnicode_FromFormat(
"<%s %s object owner=%" PY_FORMAT_THREAD_IDENT_T " count=%zu at %p>",
locked ? "locked" : "unlocked",