Skip to content

Commit 9402ea6

Browse files
authored
gh-96471: Correct docs for queue shutdown (#115838)
1 parent a0a8d9f commit 9402ea6

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

Doc/library/queue.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,12 @@ 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+
190193
Raises a :exc:`ValueError` if called more times than there were items placed in
191194
the queue.
192195

193-
Raises :exc:`ShutDown` if the queue has been shut down immediately.
194-
195196

196197
.. method:: Queue.join()
197198

@@ -202,8 +203,6 @@ fully processed by daemon consumer threads.
202203
indicate that the item was retrieved and all work on it is complete. When the
203204
count of unfinished tasks drops to zero, :meth:`join` unblocks.
204205

205-
Raises :exc:`ShutDown` if the queue has been shut down immediately.
206-
207206

208207
Example of how to wait for enqueued tasks to be completed::
209208

Lib/queue.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,11 @@ def task_done(self):
7272
have been processed (meaning that a task_done() call was received
7373
for every item that had been put() into the queue).
7474
75+
shutdown(immediate=True) calls task_done() for each remaining item in
76+
the queue.
77+
7578
Raises a ValueError if called more times than there were items
7679
placed in the queue.
77-
78-
Raises ShutDown if the queue has been shut down immediately.
7980
'''
8081
with self.all_tasks_done:
8182
unfinished = self.unfinished_tasks - 1
@@ -93,8 +94,6 @@ def join(self):
9394
to indicate the item was retrieved and all work on it is complete.
9495
9596
When the count of unfinished tasks drops to zero, join() unblocks.
96-
97-
Raises ShutDown if the queue has been shut down immediately.
9897
'''
9998
with self.all_tasks_done:
10099
while self.unfinished_tasks:
@@ -227,18 +226,17 @@ def get_nowait(self):
227226
return self.get(block=False)
228227

229228
def shutdown(self, immediate=False):
230-
'''Shut-down the queue, making queue gets and puts raise.
229+
'''Shut-down the queue, making queue gets and puts raise ShutDown.
231230
232231
By default, gets will only raise once the queue is empty. Set
233232
'immediate' to True to make gets raise immediately instead.
234233
235234
All blocked callers of put() will be unblocked, and also get()
236-
and join() if 'immediate'. The ShutDown exception is raised.
235+
and join() if 'immediate'.
237236
'''
238237
with self.mutex:
239238
self.is_shutdown = True
240239
if immediate:
241-
n_items = self._qsize()
242240
while self._qsize():
243241
self._get()
244242
if self.unfinished_tasks > 0:

0 commit comments

Comments
 (0)