@@ -102,17 +102,34 @@ Queue
102102
103103 .. method :: shutdown(immediate=False)
104104
105- Shut down the queue, making :meth: `~Queue.get ` and :meth: `~Queue.put `
105+ Put a :class: `Queue ` instance into a shutdown mode.
106+
107+ The queue can no longer grow.
108+ Future calls to :meth: `~Queue.put ` raise :exc: `QueueShutDown `.
109+ Currently blocked callers of :meth: `~Queue.put ` will be unblocked
110+ and will raise :exc: `QueueShutDown ` in the formerly blocked thread.
111+
112+ If *immediate * is false (the default), the queue can be wound
113+ down normally with :meth: `~Queue.get ` calls to extract tasks
114+ that have already been loaded.
115+
116+ And if :meth: `~Queue.task_done ` is called for each remaining task, a
117+ pending :meth: `~Queue.join ` will be unblocked normally.
118+
119+ Once the queue is empty, future calls to :meth: `~Queue.get ` will
106120 raise :exc: `QueueShutDown `.
107121
108- By default, :meth: `~Queue.get ` on a shut down queue will only
109- raise once the queue is empty. Set *immediate * to true to make
110- :meth: `~Queue.get ` raise immediately instead.
122+ If *immediate * is true, the queue is terminated immediately.
123+ The queue is drained to be completely empty and the count
124+ of unfinished tasks is reduced by the number of tasks drained.
125+ If unfinished tasks is zero, callers of :meth: `~Queue.join `
126+ are unblocked. Also, blocked callers of :meth: `~Queue.get `
127+ are unblocked and will raise :exc: `QueueShutDown ` because the
128+ queue is empty.
111129
112- All blocked callers of :meth: `~Queue.put ` and :meth: `~Queue.get `
113- will be unblocked. If *immediate * is true, a task will be marked
114- as done for each remaining item in the queue, which may unblock
115- callers of :meth: `~Queue.join `.
130+ Use caution when using :meth: `~Queue.join ` with *immediate * set
131+ to true. This unblocks the join even when no work has been done
132+ on the tasks, violating the usual invariant for joining a queue.
116133
117134 .. versionadded :: 3.13
118135
@@ -129,9 +146,6 @@ Queue
129146 call was received for every item that had been :meth: `~Queue.put `
130147 into the queue).
131148
132- ``shutdown(immediate=True) `` calls :meth: `task_done ` for each
133- remaining item in the queue.
134-
135149 Raises :exc: `ValueError ` if called more times than there were
136150 items placed in the queue.
137151
0 commit comments