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.
245245 queue is empty. Set *immediate * to true to make :meth: `~Queue.get ` raise
246246 immediately instead.
247247
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 `.
250252
251253 .. versionadded :: 3.13
252254
Original file line number Diff line number Diff line change @@ -239,8 +239,9 @@ def shutdown(self, immediate=False):
239239 By default, gets will only raise once the queue is empty. Set
240240 'immediate' to True to make gets raise immediately instead.
241241
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().
244245 '''
245246 with self .mutex :
246247 self .is_shutdown = True
@@ -249,9 +250,10 @@ def shutdown(self, immediate=False):
249250 self ._get ()
250251 if self .unfinished_tasks > 0 :
251252 self .unfinished_tasks -= 1
252- self .not_empty .notify_all ()
253253 # release all blocked threads in `join()`
254254 self .all_tasks_done .notify_all ()
255+ # All getters need to re-check queue-empty to raise ShutDown
256+ self .not_empty .notify_all ()
255257 self .not_full .notify_all ()
256258
257259 # 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):
636636
637637 self .assertEqual (results , [True ]* len (thrds ))
638638
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+
639656
640657class QueueTest (BaseQueueTestMixin ):
641658
You can’t perform that action at this time.
0 commit comments