queue – Queue class¶
A major difference is that queues in this module operate as channels when
initialized with maxsize of zero. In such case, both
Queue.put() always blocks until
a call to
Queue.get() retrieves the item.
An interesting difference, made possible because of greenthreads, is
Queue.full() can be
used as indicators of whether the subsequent
Queue.put() will not block. The new methods
Queue.putting() report on the number of greenthreads blocking
Create a queue object with a given maximum size.
If maxsize is less than zero or
None, the queue size is infinite.
Queue(0)is a channel, that is, its
put()method always blocks until the item is delivered. (This is unlike the standard
Stdlib_Queue, where 0 means infinite size).
In all other respects, this Queue class resembles the standard library,
Block until all items in the queue have been gotten and processed.
The count of unfinished tasks goes up whenever an item is added to the queue. The count goes down whenever a consumer thread calls
task_done()to indicate that the item was retrieved and all work on it is complete. When the count of unfinished tasks drops to zero,
Indicate that a formerly enqueued task is complete. Used by queue consumer threads. For each
getused to fetch a task, a subsequent call to
task_done()tells the queue that the processing on the task is complete.
ValueErrorif called more times than there were items placed in the queue.
A subclass of
Queuethat retrieves entries in priority order (lowest first).
Entries are typically tuples of the form:
(priority number, data).
A subclass of
Queuethat retrieves most recently added entries first.
This is a variant of Queue that behaves mostly like the standard
Stdlib_Queue. It differs by not supporting the
joinmethods, and is a little faster for not having that overhead.
Trueif the queue is empty,
Trueif the queue is full,
Queue(None)is never full.
Remove and return an item from the queue.
If optional args block is true and timeout is
None(the default), block if necessary until an item is available. If timeout is a positive number, it blocks at most timeout seconds and raises the
Emptyexception if no item was available within that time. Otherwise (block is false), return an item if one is immediately available, else raise the
Emptyexception (timeout is ignored in that case).
Remove and return an item from the queue without blocking.
Only get an item if one is immediately available. Otherwise raise the
Returns the number of greenthreads that are blocked waiting on an empty queue.
put(item, block=True, timeout=None)¶
Put an item into the queue.
If optional arg block is true and timeout is
None(the default), block if necessary until a free slot is available. If timeout is a positive number, it blocks at most timeout seconds and raises the
Fullexception if no free slot was available within that time. Otherwise (block is false), put an item on the queue if a free slot is immediately available, else raise the
Fullexception (timeout is ignored in that case).
Put an item into the queue without blocking.
Only enqueue the item if a free slot is immediately available. Otherwise raise the
Returns the number of greenthreads that are blocked waiting to put items into the queue.
Return the size of the queue.
Resizes the queue’s maximum size.
If the size is increased, and there are putters waiting, they may be woken up.
Exception raised by Queue.put(block=0)/put_nowait().
Exception raised by Queue.get(block=0)/get_nowait().