Skip to content

Commit 9072c6f

Browse files
committed
Fix join after task-done with no get
Also shut down before put-join in shutdown-put-join tests. Also remove indent
1 parent 3570bd8 commit 9072c6f

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

Lib/queue.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ def shutdown(self, immediate=False):
241241
n_items = self._qsize()
242242
while self._qsize():
243243
self._get()
244-
self.unfinished_tasks -= n_items
244+
self.unfinished_tasks = max(self.unfinished_tasks - n_items, 0)
245245
self.not_empty.notify_all()
246246
# release all blocked threads in `join()`
247247
self.all_tasks_done.notify_all()

Lib/test/test_queue.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -575,14 +575,13 @@ def _shutdown_put_join(self, immediate):
575575
for func, params in thrds:
576576
threads.append(threading.Thread(target=func, args=params))
577577
threads[-1].start()
578-
if not immediate or immediate: # TODO: dedent (minimising Git diff)
579-
self.assertEqual(q.unfinished_tasks, nb)
580-
for i in range(nb):
581-
t = threading.Thread(target=q.task_done)
582-
t.start()
583-
threads.append(t)
584-
go.set()
578+
self.assertEqual(q.unfinished_tasks, nb)
579+
for i in range(nb):
580+
t = threading.Thread(target=q.task_done)
581+
t.start()
582+
threads.append(t)
585583
q.shutdown(immediate)
584+
go.set()
586585
for t in threads:
587586
t.join()
588587

0 commit comments

Comments
 (0)