Master threads queue Three uses of
The duration of this section needs to be controlled 5 Within minutes
queue is especially useful in threaded programming when information must be exchanged safely between multiple threads.
There are three different uses
class queue.Queue(maxsize=0) # queue : fifo
import queue
q=queue.Queue()
q.put('first')
q.put('second')
q.put('third')
print(q.get())
print(q.get())
print(q.get())
'''
result ( fifo ):
first
second
third
'''
class queue.LifoQueue(maxsize=0) # Stack :last in fisrt out
import queue
q=queue.LifoQueue()
q.put('first')
q.put('second')
q.put('third')
print(q.get())
print(q.get())
print(q.get())
'''
result ( Last in, first out ):
third
second
first
'''
class queue.PriorityQueue(maxsize=0) # Priority queue : Priority queues can be set when storing data
import queue
q=queue.PriorityQueue()
#put Enter a tuple , The first element of a tuple is priority ( It's usually numbers , It can also be a comparison between numbers ), The smaller the number, the higher the priority
q.put((20,'a'))
q.put((10,'b'))
q.put((30,'c'))
print(q.get())
print(q.get())
print(q.get())
'''
result ( The smaller the number, the higher the priority , A high priority team ):
(10, 'b')
(20, 'a')
(30, 'c')
'''