The Queue module implements a multi-producer, multi-consumer FIFO queue. It is especially useful in threads programming when information must be exchanged safely between multiple threads. The Queue class in this module implements all the required locking semantics. It depends on the availability of thread support in Python.
The Queue module defines the following class and exception:
class Queue( | maxsize) |
- exception Empty
- Exception raised when non-blocking get() (or get_nowait()) is called on a Queue object which is empty or locked.
- exception Full
- Exception raised when non-blocking put() (or put_nowait()) is called on a Queue object which is full or locked.
Queue Objects
Class Queue implements queue objects and has the methods described below. This class can be derived from in order to implement other queue organizations (e.g. stack) but the inheritable interface is not described here. See the source code for details. The public methods are:
qsize( | ) |
empty( | ) |
True
if the queue is empty, False
otherwise. Becauseof multithreading semantics, this is not reliable.
full( | ) |
True
if the queue is full, False
otherwise. Because of multithreading semantics, this is not reliable.
put( | item[, block[, timeout]] |
New in version 2.3: the timeout parameter.
put_nowait( | item) |
put(item, False)
.
get( | [block[, timeout]]) |
New in version 2.3: the timeout parameter.
get_nowait( | ) |
get(False)
.