FIFO Queue (first-in-one-out)
#!/usr/bin/env python#-*-coding:utf-8-*-__author__='Zhoufeng'#FIFO queueImportQueueq=queue. Queue (3)#define a 3-position queue#using the Put method to add elements to the queue, you need to consider whether you can drop the problem#if it does not fit, the default will be blocked (block=true), when blocking can define the time-out (timeout=5)#You can use the Block=false setting to not block immediate errorsQ.put (11) Q.put (22) Q.put (33)Print(Q.empty ())#determines whether the queue is empty, returns TRUE if NULL is returned false, NOT NULLPrint(Q.qsize ())#number of elements in output queueQ.put (44,block=true,timeout=5)#using the Get method to fetch data from a queue, you need to consider whether there is a problem with data that is desirable#If no data is desirable, the default is blocked (block=true), when blocking can define time-out (timeout=2)#You can use the Block=false setting to not block immediate errorsPrint(Q.get ())Print(Q.get ())Print(Q.get ())Print(Q.get (block=true,timeout=2))#There are also join and Task_done methods, both of which are used in pairs#The join method is used to block the process from continuing to execute, and when the task in the queue finishes, no longer blocks#How does the interpreter know that the task is done in the queue? Explicitly tells the interpreter that a task has been executed by means of the Task_done methodQue=queue. Queue (3)#defines a 3-position queue objectQue.put (11) Que.put (22) Que.put (33) Que.get () Que.task_done ()#tell the interpreter that a task has been executed.Que.get () que.task_done ( )#tell the interpreter that a task has been executed.Que.join ()
View Code
Second, Stack (last in first out)
Use queue. Lifoqueue () Build stack
Third, priority queue
Use queue. Priorityqueue () Generate priority queue
Four, two-way queue
Using Queue.deque () to generate a two-way queue
Python---Common data queues