A queue is a data structure that is secure and data-safe. The list of capable things in the queue is capable. The list is thread insecure, so it can be said that the queue is for multithreaded occurrences.
The data structure is used to store it, except that the various data structures are stored in different ways. For example: Collections, queues, mappings
List: Storing by index value
Dictionary: A hash table stored by key value
List.pop () #按索引删除
List.remove (' str ') #按值删除
Import # Thread Queue Q # default FIFO q=queue. Queue (5) can only put 5 elements q.put (q.put) ('hello') q.put ({' name':'Lee'})
Print (Q.qsize ())
Print (Q.full ())
Print (Q.empty ())
while 1: Data = q.get () print print ( " ------ " )
Import Queueq=queue. Lifoqueue () # LIFO mode q.put (a) q.put ('hello') q.put ( {'name':'Lee'})
Print (Q.qsize ())
Print (Q.full ())
Print (Q.empty ())
while 1: Data=printprint('------' )
Import queue
Q=queue. Priorityqueue () #优先级模式
Q.put ([3,12])
Q.put ([2, ' hello '])
Q.put ([4,{' name ': ' Lee '}])
Print (Q.qsize ())
Print (Q.full ())
Print (Q.empty ())
While 1:
Data=q.get (block=false) #相当于q. get_nowait ()
Print (data)
Print ('------')
Q.join () #意味着等待队列为空, and then perform another operation
python-Thread Queue