File tree Expand file tree Collapse file tree 3 files changed +26
-5
lines changed Expand file tree Collapse file tree 3 files changed +26
-5
lines changed Original file line number Diff line number Diff line change @@ -245,8 +245,10 @@ them down.
245
245
queue is empty. Set *immediate * to true to make :meth: `~Queue.get ` raise
246
246
immediately instead.
247
247
248
- All blocked callers of :meth: `~Queue.put ` will be unblocked. If *immediate *
249
- is true, also unblock callers of :meth: `~Queue.get ` and :meth: `~Queue.join `.
248
+ All blocked callers of :meth: `~Queue.put ` and :meth: `~Queue.get ` will be
249
+ unblocked. If *immediate * is true, a task will be marked as done for each
250
+ remaining item in the queue, which may unblock callers of
251
+ :meth: `~Queue.join `.
250
252
251
253
.. versionadded :: 3.13
252
254
Original file line number Diff line number Diff line change @@ -239,8 +239,9 @@ def shutdown(self, immediate=False):
239
239
By default, gets will only raise once the queue is empty. Set
240
240
'immediate' to True to make gets raise immediately instead.
241
241
242
- All blocked callers of put() will be unblocked, and also get()
243
- and join() if 'immediate'.
242
+ All blocked callers of put() and get() will be unblocked. If
243
+ 'immediate', a task is marked as done for each item remaining in
244
+ the queue, which may unblock callers of join().
244
245
'''
245
246
with self .mutex :
246
247
self .is_shutdown = True
@@ -249,9 +250,10 @@ def shutdown(self, immediate=False):
249
250
self ._get ()
250
251
if self .unfinished_tasks > 0 :
251
252
self .unfinished_tasks -= 1
252
- self .not_empty .notify_all ()
253
253
# release all blocked threads in `join()`
254
254
self .all_tasks_done .notify_all ()
255
+ # All getters need to re-check queue-empty to raise ShutDown
256
+ self .not_empty .notify_all ()
255
257
self .not_full .notify_all ()
256
258
257
259
# Override these methods to implement other queue organizations
Original file line number Diff line number Diff line change @@ -636,6 +636,23 @@ def test_shutdown_get_task_done_join(self):
636
636
637
637
self .assertEqual (results , [True ]* len (thrds ))
638
638
639
+ def test_shutdown_pending_get (self ):
640
+ def get ():
641
+ try :
642
+ results .append (q .get ())
643
+ except Exception as e :
644
+ results .append (e )
645
+
646
+ q = self .type2test ()
647
+ results = []
648
+ get_thread = threading .Thread (target = get )
649
+ get_thread .start ()
650
+ q .shutdown (immediate = False )
651
+ get_thread .join (timeout = 10.0 )
652
+ self .assertFalse (get_thread .is_alive ())
653
+ self .assertEqual (len (results ), 1 )
654
+ self .assertIsInstance (results [0 ], self .queue .ShutDown )
655
+
639
656
640
657
class QueueTest (BaseQueueTestMixin ):
641
658
You can’t perform that action at this time.
0 commit comments