Queue is usually used for data exchange between threads in Python. The queue
module
provides manipulations of Queues.
Create a Queue object:
>>> import queue >>> q = queue.Queue(maxsize=5) >>> q
(queue.Queue object at 0x024D65B0)Put item into the queue:
>>> q.put(8)
Remove an item from the queue:
>>> q.get()
8
queue
module manipulates 3 types of queue:queue.Queue(maxsize=0)
: FIFO queue, first in first out, the first tasks added are the first retrieved.queue.LifoQueue(maxsize=0)
: last in first out.queue.PriorityQueue(maxsize=0)
: the lowest valued entries are retrieved first.queue
module methods list: