bpo-32208: update threading.Semaphore docs and add unit test (#4709)
* fix issue32208: update threading.Semaphore docs and add unit test to validate correct behavior
* add test for blocking
* Update threading.rst
* semaphore: remove documentation validation tests and move 'return value' test to BaseSemaphore
diff --git a/Lib/test/lock_tests.py b/Lib/test/lock_tests.py
index a1ea96d..5b1f033 100644
--- a/Lib/test/lock_tests.py
+++ b/Lib/test/lock_tests.py
@@ -629,13 +629,14 @@
sem = self.semtype(7)
sem.acquire()
N = 10
+ sem_results = []
results1 = []
results2 = []
phase_num = 0
def f():
- sem.acquire()
+ sem_results.append(sem.acquire())
results1.append(phase_num)
- sem.acquire()
+ sem_results.append(sem.acquire())
results2.append(phase_num)
b = Bunch(f, 10)
b.wait_for_started()
@@ -659,6 +660,7 @@
# Final release, to let the last thread finish
sem.release()
b.wait_for_finished()
+ self.assertEqual(sem_results, [True] * (6 + 7 + 6 + 1))
def test_try_acquire(self):
sem = self.semtype(2)