mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
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
This commit is contained in:
parent
961dbe0548
commit
a0374dd34a
2 changed files with 17 additions and 15 deletions
|
@ -629,13 +629,14 @@ class BaseSemaphoreTests(BaseTestCase):
|
|||
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 @@ class BaseSemaphoreTests(BaseTestCase):
|
|||
# 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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue