Python queue Function
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:q.qsize(): return the size of the Queue
q.empty(): If the Queue is empty, return True, else False
q.full(): If the Queue is full, return True, else False
q.get([block[,timeout]]): get Queue, timeout is the waiting time
q.get_nowait(): q.put([block[,timeout]]): put in Queue, timeout is the waiting time
q.put_nowait(): q.task_done(): formerly enqueued task is complete q.join(): Blocks until all items in the Queue have been processed