Python并发编程:多线程-线程queue
一 线程queue
有三种不同的用法
class queue.Queue(maxsize=0) # 队列:先进先出
import queue q = queue.Queue() q.put('first') q.put('second') q.put('third') print(q.get()) print(q.get()) print(q.get()) 结果: first second third
class queue.LifoQueue(maxsize=0) # 堆栈:后进先出
import queue q = queue.LifoQueue() q.put('first') q.put('second') q.put('third') print(q.get()) print(q.get()) print(q.get()) 结果: third second first
class queue.PriorityQueue(maxsize=0) #优先级队列:存储数据时可设置优先级的队列
import queue q = queue.PriorityQueue() q.put((20, 'a')) q.put((10, 'b')) q.put((30, 'c')) print(q.get()) print(q.get()) print(q.get())