aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/_test_multiprocessing.py
diff options
context:
space:
mode:
authorsobolevn <mail@sobolevn.me>2025-04-08 11:14:12 +0300
committerGitHub <noreply@github.com>2025-04-08 11:14:12 +0300
commitf7305a06c7a322d23b39ad9d16af814d467624c6 (patch)
tree8a25dede6c059e01ae98c63d737ac0d0c1987b58 /Lib/test/_test_multiprocessing.py
parent6cd1d6c6b142697fb72f422b7b448c27ebc30534 (diff)
downloadcpython-f7305a06c7a322d23b39ad9d16af814d467624c6.tar.gz
cpython-f7305a06c7a322d23b39ad9d16af814d467624c6.zip
gh-115942: Add `locked` to several multiprocessing locks (#115944)
Co-authored-by: mpage <mpage@cs.stanford.edu> Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Diffstat (limited to 'Lib/test/_test_multiprocessing.py')
-rw-r--r--Lib/test/_test_multiprocessing.py17
1 files changed, 14 insertions, 3 deletions
diff --git a/Lib/test/_test_multiprocessing.py b/Lib/test/_test_multiprocessing.py
index dcce57629ef..1cd5704905f 100644
--- a/Lib/test/_test_multiprocessing.py
+++ b/Lib/test/_test_multiprocessing.py
@@ -1486,8 +1486,10 @@ class _TestLock(BaseTestCase):
def test_lock(self):
lock = self.Lock()
self.assertEqual(lock.acquire(), True)
+ self.assertTrue(lock.locked())
self.assertEqual(lock.acquire(False), False)
self.assertEqual(lock.release(), None)
+ self.assertFalse(lock.locked())
self.assertRaises((ValueError, threading.ThreadError), lock.release)
@staticmethod
@@ -1549,16 +1551,23 @@ class _TestLock(BaseTestCase):
def test_rlock(self):
lock = self.RLock()
self.assertEqual(lock.acquire(), True)
+ self.assertTrue(lock.locked())
self.assertEqual(lock.acquire(), True)
self.assertEqual(lock.acquire(), True)
self.assertEqual(lock.release(), None)
+ self.assertTrue(lock.locked())
self.assertEqual(lock.release(), None)
self.assertEqual(lock.release(), None)
+ self.assertFalse(lock.locked())
self.assertRaises((AssertionError, RuntimeError), lock.release)
def test_lock_context(self):
- with self.Lock():
- pass
+ with self.Lock() as locked:
+ self.assertTrue(locked)
+
+ def test_rlock_context(self):
+ with self.RLock() as locked:
+ self.assertTrue(locked)
class _TestSemaphore(BaseTestCase):
@@ -6254,6 +6263,7 @@ class TestSyncManagerTypes(unittest.TestCase):
@classmethod
def _test_lock(cls, obj):
obj.acquire()
+ obj.locked()
def test_lock(self, lname="Lock"):
o = getattr(self.manager, lname)()
@@ -6265,8 +6275,9 @@ class TestSyncManagerTypes(unittest.TestCase):
def _test_rlock(cls, obj):
obj.acquire()
obj.release()
+ obj.locked()
- def test_rlock(self, lname="Lock"):
+ def test_rlock(self, lname="RLock"):
o = getattr(self.manager, lname)()
self.run_worker(self._test_rlock, o)