mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-134323: Fix the new threading.RLock.locked
method (#134368)
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
This commit is contained in:
parent
bd4046f4f8
commit
3effede97c
4 changed files with 29 additions and 4 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue