@@ -187,9 +187,6 @@ fully processed by daemon consumer threads.
187187   processed (meaning that a :meth: `task_done ` call was received for every item
188188   that had been :meth: `put ` into the queue).
189189
190-    ``shutdown(immediate=True) `` calls :meth: `task_done ` for each remaining item
191-    in the queue.
192- 
193190   Raises a :exc: `ValueError ` if called more times than there were items placed in
194191   the queue.
195192
@@ -204,6 +201,9 @@ fully processed by daemon consumer threads.
204201   count of unfinished tasks drops to zero, :meth: `join ` unblocks.
205202
206203
204+ Waiting for task completion
205+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 
206+ 
207207Example of how to wait for enqueued tasks to be completed::
208208
209209    import threading 
@@ -233,22 +233,38 @@ Example of how to wait for enqueued tasks to be completed::
233233Terminating queues
234234^^^^^^^^^^^^^^^^^^ 
235235
236- :class: `Queue ` objects can be made to prevent further interaction by shutting 
237- them down .
236+ When no longer needed,  :class: `Queue ` objects can be wound down 
237+ until empty or terminated immediately with a hard shutdown .
238238
239239.. method :: Queue.shutdown(immediate=False) 
240240
241-    Shut down the queue, making :meth: `~Queue.get ` and :meth: `~Queue.put ` raise
242-    :exc: `ShutDown `.
241+    Put a :class: `Queue ` instance into a shutdown mode.
242+ 
243+    The queue can no longer grow.
244+    Future calls to :meth: `~Queue.put ` raise :exc: `ShutDown `.
245+    Currently blocked callers of :meth: `~Queue.put ` will be unblocked
246+    and will raise :exc: `ShutDown ` in the formerly blocked thread.
247+ 
248+    If *immediate * is false (the default), the queue can be wound
249+    down normally with :meth: `~Queue.get ` calls to extract tasks
250+    that have already been loaded.
251+ 
252+    And if :meth: `~Queue.task_done ` is called for each remaining task, a
253+    pending :meth: `~Queue.join ` will be unblocked normally.
254+ 
255+    Once the queue is empty, future calls to :meth: `~Queue.get ` will
256+    raise :exc: `ShutDown `.
243257
244-    By default, :meth: `~Queue.get ` on a shut down queue will only raise once the
245-    queue is empty. Set *immediate * to true to make :meth: `~Queue.get ` raise
246-    immediately instead.
258+    If *immediate * is true, the queue is terminated immediately.
259+    The queue is drained to be completely empty.  All callers of
260+    :meth: `~Queue.join ` are unblocked regardless of the number
261+    of unfinished tasks.  Blocked callers of :meth: `~Queue.get `
262+    are unblocked and will raise :exc: `ShutDown ` because the
263+    queue is empty.
247264
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 `.
265+    Use caution when using :meth: `~Queue.join ` with *immediate * set
266+    to true. This unblocks the join even when no work has been done
267+    on the tasks, violating the usual invariant for joining a queue.
252268
253269   .. versionadded :: 3.13 
254270
0 commit comments