The queue module in Python3 implements multi-producer, Multi-consumer queue, especially for the secure exchange of information between multiple threads, There are three main classes
Queue. Queue (maxsize=0)
Constructs a FIFO (first-in-one-out) queue
Queue. Lifoqueue (maxsize=0)
Constructs a LIFO (last in, first Out) queue
Queue. Priorityqueue (maxsize=0)
Constructs a queue with priority, stores a tuple (n, value), n is a number, and the number is lower, the higher the level
This module defines two Exceptions.
Queue. Empty
If the queue is empty, continuing to call Non-blocking get_nowait () throws an exception
Queue. Full
If the queue is full, continuing to call Non-blocking put_nowait () throws an exception
ImportQueue#The following three queues can be set to a maximum length of maxsize, which is infinitely large by defaultPrint("-------------queue. Queue----------------")#thread message queuing, FIFO (lifo)Q =Queue. Queue () Q.put (" one") Q.put (" both") Q.put ("three")Print(q.get ())Print(q.get ())Print(q.get ())#print (q.get (timeout=3)) # There is no data in the queue, it blocksPrint("-------------queue. lifoqueue----------------")#thread message queuing, LIFO (lifo)LQ =Queue. Lifoqueue () Lq.put (" one") Lq.put (" both") Lq.put ("three")Print(lq.get ())Print(lq.get ())Print(lq.get ())Print("-------------queue. priorityqueue----------------")#thread message queuing, priorityqueue (priority queue: The smaller the number, the higher the Priority)PQ =Queue. Priorityqueue () pq.put (1,"Jet")) Pq.put (3,"Jack")) Pq.put (2,"Judy"))Print(pq.get ())Print(pq.get ())Print(pq.get ())
View Code
Resources
Http://python.usyiyi.cn/translate/python_352/library/queue.html
Python3-queue module-synchronization Queue