62
62
Remove and return an item from the queue. If queue is empty,
63
63
wait until an item is available.
64
64
65
+ Raises :exc: `QueueShutDown ` if the queue has been shut down and
66
+ is empty, or if the queue has been shut down immediately.
67
+
65
68
.. method :: get_nowait()
66
69
67
70
Return an item if one is immediately available, else raise
82
85
Put an item into the queue. If the queue is full, wait until a
83
86
free slot is available before adding the item.
84
87
88
+ Raises :exc: `QueueShutDown ` if the queue has been shut down.
89
+
85
90
.. method :: put_nowait(item)
86
91
87
92
Put an item into the queue without blocking.
92
97
93
98
Return the number of items in the queue.
94
99
100
+ .. method :: shutdown(immediate=False)
101
+
102
+ Shut down the queue, making :meth: `~Queue.get ` and :meth: `~Queue.put `
103
+ raise :exc: `QueueShutDown `.
104
+
105
+ By default, :meth: `~Queue.get ` on a shut down queue will only
106
+ raise once the queue is empty. Set *immediate * to true to make
107
+ :meth: `~Queue.get ` raise immediately instead.
108
+
109
+ All blocked callers of :meth: `~Queue.put ` and :meth: `~Queue.get `
110
+ will be unblocked. If *immediate * is true, a task will be marked
111
+ as done for each remaining item in the queue, which may unblock
112
+ callers of :meth: `~Queue.join `.
113
+
114
+ .. versionadded :: 3.13
115
+
95
116
.. method :: task_done()
96
117
97
118
Indicate that a formerly enqueued task is complete.
@@ -105,6 +126,9 @@ Queue
105
126
call was received for every item that had been :meth: `~Queue.put `
106
127
into the queue).
107
128
129
+ ``shutdown(immediate=True) `` calls :meth: `task_done ` for each
130
+ remaining item in the queue.
131
+
108
132
Raises :exc: `ValueError ` if called more times than there were
109
133
items placed in the queue.
110
134
@@ -145,6 +169,14 @@ Exceptions
145
169
on a queue that has reached its *maxsize *.
146
170
147
171
172
+ .. exception :: QueueShutDown
173
+
174
+ Exception raised when :meth: `~Queue.put ` or :meth: `~Queue.get ` is
175
+ called on a queue which has been shut down.
176
+
177
+ .. versionadded :: 3.13
178
+
179
+
148
180
Examples
149
181
========
150
182
0 commit comments