first in first out mode
import queue #Thread queue q = queue.Queue() #First in , first out, the data stored first will be taken out first. If there is a number in (), such as 5, it means the amount of data that can be put in q. q.put( 12 ) q.put('hello') q.put({'name':'doudou'}) q.put( 34,False) #Meaning , if the queue is full. put can't go in, it will return print (q.qsize()) #The specific value in the queue print (q.empty()) #Whether it is empty print (q.full()) #Whether it is full while 1: data = q.get(block = False) #When the queue is fetched, if it continues to fetch, it will return print (data) print ( ' --------- ' )
first in last out mode
import queue q = queue.LifoQueue() q.put(12) q.put('hello') q.put({'name':'doudou'}) while 1: data = q.get(block=False) #When the queue is fetched, if it continues to fetch, it will return print (data) print ( ' --------- ' )
priority mode
import queue q = queue.PriorityQueue() q.put([ 3,12]) #The smaller the first number in the list, the higher the priority q.put([2, ' hello ' ]) q.put([4,{'name':'doudu'}]) while 1: data = q.get() #When the queue is fetched, if it continues to fetch, it will return print (data) print ( ' --------- ' )