Skip to content

Commit

Permalink
Update comments.
Browse files Browse the repository at this point in the history
Fix start value of range.
Change `self.assertLessEqual` to `self.assertEqual`.
  • Loading branch information
YvesDup committed Mar 15, 2024
1 parent e0be6b5 commit e4e880b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
18 changes: 9 additions & 9 deletions Lib/test/test_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ def _write_msg_thread(self, q, n, results,
# Wait for the barrier to be complete.
barrier_start.wait()

for i in range(i, n):
for i in range(i_when_exec_shutdown//2, n):
try:
q.put((i, "YDLO"))
except self.queue.ShutDown:
Expand All @@ -336,7 +336,7 @@ def _write_msg_thread(self, q, n, results,

# Trigger queue shutdown.
if i == i_when_exec_shutdown:
# Only once thread do it.
# Only one thread should call shutdown().
if not event_shutdown.is_set():
event_shutdown.set()
results.append(True)
Expand Down Expand Up @@ -370,7 +370,7 @@ def _join_thread(self, q, barrier_start):
def _shutdown_all_methods_in_many_threads(self, immediate):
# Run a 'multi-producers/consumers queue' use case,
# with enough items into the queue.
# When shutdown, all running threads will be concerned.
# When shutdown, all running threads will be joined.
q = self.type2test()
ps = []
res_puts = []
Expand All @@ -382,11 +382,11 @@ def _shutdown_all_methods_in_many_threads(self, immediate):
nb_msgs = 1024*64
nb_msgs_w = nb_msgs // write_threads
when_exec_shutdown = nb_msgs_w // 2
# Use of a `threading.Barrier`` to ensure that
# all `_write_msg_threads`put their part of items into the queue
# all `_read_msg_thread` get at least one itme from the queue,
# and keep on running until shutdown.
# The `_join_thread` is started only when shutdown is emmediate.
# Use of a Barrier to ensure that
# - all write threads put all their items into the queue,
# - all read thread get at least one item from the queue,
# and keep on running until shutdown.
# The join thread is started only when shutdown is immediate.
nparties = write_threads + read_threads
if immediate:
nparties += join_threads
Expand All @@ -410,7 +410,7 @@ def _shutdown_all_methods_in_many_threads(self, immediate):
thread.join()

self.assertTrue(True in res_puts)
self.assertLessEqual(res_gets.count(True), read_threads)
self.assertEqual(res_gets.count(True), read_threads)
if immediate:
self.assertListEqual(res_shutdown, [True])
self.assertTrue(q.empty())
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Fix a hang test in ``test_queue.GenericQueueTest.test_shutdown_[immediate_]all_methods_in_many_threads`` unittests. This unit test is dedicated to the new **shutdown** feature in the threading queue.
Fix a hang in ``test_queue.GenericQueueTest.test_shutdown_[immediate_]all_methods_in_many_threads``.
This unit test is dedicated to the new ``shutdown`` feature in the threading queue.

0 comments on commit e4e880b

Please sign in to comment.