Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 98ab21c

Browse filesBrowse files
authored
gh-116631: Fix race condition in test_shutdown_immediate_put_join (#116670)
The test case had a race condition: if `q.task_done()` was executed after `shutdown(immediate=True)`, then it would raise an exception because the immediate shutdown already emptied the queue. This happened rarely with the GIL (due to the switching interval), but frequently in the free-threaded build.
1 parent 25684e7 commit 98ab21c
Copy full SHA for 98ab21c

File tree

Expand file treeCollapse file tree

1 file changed

+11
-6
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+11
-6
lines changed

‎Lib/test/test_queue.py

Copy file name to clipboardExpand all lines: Lib/test/test_queue.py
+11-6Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,6 @@ def _shutdown_put_join(self, immediate):
567567
results = []
568568
go = threading.Event()
569569
q.put("Y")
570-
nb = q.qsize()
571570
# queue not fulled
572571

573572
thrds = (
@@ -578,13 +577,19 @@ def _shutdown_put_join(self, immediate):
578577
for func, params in thrds:
579578
threads.append(threading.Thread(target=func, args=params))
580579
threads[-1].start()
581-
self.assertEqual(q.unfinished_tasks, nb)
582-
for i in range(nb):
583-
t = threading.Thread(target=q.task_done)
584-
t.start()
585-
threads.append(t)
580+
self.assertEqual(q.unfinished_tasks, 1)
581+
586582
q.shutdown(immediate)
587583
go.set()
584+
585+
if immediate:
586+
with self.assertRaises(self.queue.ShutDown):
587+
q.get_nowait()
588+
else:
589+
result = q.get()
590+
self.assertEqual(result, "Y")
591+
q.task_done()
592+
588593
for t in threads:
589594
t.join()
590595

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.