gh-134323: Fix the new threading.RLock.locked method (#134368)

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
This commit is contained in:
Duprat 2025-05-22 15:48:24 +02:00 committed by GitHub
parent bd4046f4f8
commit 3effede97c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 29 additions and 4 deletions

View file

@ -370,6 +370,24 @@ class RLockTests(BaseLockTests):
lock.release()
self.assertFalse(lock.locked())
def test_locked_with_2threads(self):
# see gh-134323: check that a rlock which
# is acquired in a different thread,
# is still locked in the main thread.
result = []
rlock = self.locktype()
self.assertFalse(rlock.locked())
def acquire():
result.append(rlock.locked())
rlock.acquire()
result.append(rlock.locked())
with Bunch(acquire, 1):
pass
self.assertTrue(rlock.locked())
self.assertFalse(result[0])
self.assertTrue(result[1])
def test_release_save_unacquired(self):
# Cannot _release_save an unacquired lock
lock = self.locktype()