浅谈python标准库中的queue队列模块

queue(队列)是python标准库中的模块之一,其定义:A multi-producer, multi-consumer queue.(多生产者、多消费者队列) ;主要用来在生产者和消费者线程之间的信息传递

队列类型:

浅谈python标准库中的queue队列模块

常用方法:

 
put() 存数据
get() 获取数据
empty() 判断队列是否为空
qsize() 显示队列中真实存在元素的长度
maxsize() 最大支持队列长度
join() 阻塞直到队列为空,继续执行join()后面的任务
full() 检查队列是否已满

 

  • 单向队列 queue.Queue()  (先入先出)

浅谈python标准库中的queue队列模块浅谈python标准库中的queue队列模块

 

  • 后进先出队列  queue.LifoQueue()      (与java的栈类似)

浅谈python标准库中的queue队列模块浅谈python标准库中的queue队列模块

  • 优先级队列 queue.PriorityQueue()

浅谈python标准库中的queue队列模块浅谈python标准库中的queue队列模块

  • 双向队列 queue.deque()

浅谈python标准库中的queue队列模块浅谈python标准库中的queue队列模块