https://stackoverflow.com/questions/717148/queue-queue-vs-collections-deque/717199#717199

Queue,Queue 用于多线程之间,无需lock的通信;

collections.deque 用于实现数据结构中的queue, 或两端都可以实现queue的功能。

Queue.Queue and collections.deque serve different purposes. Queue.Queue is intended for allowing different threads to communicate using queued messages/data, whereas collections.deque is simply intended as a datastructure. That's why Queue.Queue has methods like put_nowait()get_nowait(), and join(), whereas collections.deque doesn't. Queue.Queue isn't intended to be used as a collection, which is why it lacks the likes of the inoperator.

It boils down to this: if you have multiple threads and you want them to be able to communicate without the need for locks, you're looking for Queue.Queue; if you just want a queue or a double-ended queue as a datastructure, use collections.deque.

Finally, accessing and manipulating the internal deque of a Queue.Queue is playing with fire - you really don't want to be doing that.

[python] Queue.Queue vs. collections.deque的更多相关文章

  1. python基础 — Queue 队列

    queue介绍 queue是python中的标准库,俗称队列. 在python中,多个线程之间的数据是共享的,多个线程进行数据交换的时候,不能够保证数据的安全性和一致性,所以当多个线程需要进行数据交换 ...

  2. python队列Queue

    Queue Queue是python标准库中的线程安全的队列(FIFO)实现,提供了一个适用于多线程编程的先进先出的数据结构,即队列,用来在生产者和消费者线程之间的信息传递 基本FIFO队列 clas ...

  3. Python之Queue模块

    Queue 1.创建一个“队列”对象 >>> import Queue >>> queue = Queue.Queue(maxsize=100) >>& ...

  4. Python中Queue模块及多线程使用

    Python的Queue模块提供一种适用于多线程编程的FIFO实现.它可用于在生产者(producer)和消费者(consumer)之间线程安全(thread-safe)地传递消息或其它数据,因此多个 ...

  5. python之Queue

    一.多进程的消息队列 “消息队列”是在消息的传输过程中保存消息的容器 消息队列最经典的用法就是消费者和生成者之间通过消息管道来传递消息,消费者和生成者是不通的进程.生产者往管道中写消息,消费者从管道中 ...

  6. python socket非阻塞及python队列Queue

    一. python非阻塞编程的settimeout与setblocking+select 原文:www.th7.cn/Program/Python/201406/214922.shtml 侧面认证Py ...

  7. Python之queue模块以及生产消费者模型

    队列 队列类似于一条管道,元素先进先出,进put(arg),取get() 有一点需要注意的是:队列都是在内存中操作,进程退出,队列清空,另外,队列也是一个阻塞的形态. 队列分类 队列有很多中,但都依赖 ...

  8. python之保留有限的历史记录(collections.deque)

    1.deque(maxlen=N)创建一个固定长度的队列,当有新的记录加入而队列已经满时,会自动移除老的记录. from collections import deque q = deque(maxl ...

  9. Python队列queue模块

    Python中queue模块常用来处理队列相关问题 队列常用于生产者消费者模型,主要功能为提高效率和程序解耦 1. queue模块的基本使用和相关说明 # -*- coding:utf-8 -*- # ...

随机推荐

  1. 设计模式 - 抽象工厂模式(abstract factory pattern) 具体解释

    抽象工厂模式(abstract factory pattern) 详细解释 本文地址: http://blog.csdn.net/caroline_wendy/article/details/2709 ...

  2. Linux内存管理-高端内存(二)

    在支持MMU的32位处理器平台上,Linux系统中的物理存储空间和虚拟存储空间的地址范围分别都是从0x00000000到0xFFFFFFFF,共4GB,但物理存储空间与虚拟存储空间布局完全不同.Lin ...

  3. CSS节选——选择器

    CSS,cascading style sheet,层叠样式表,请留意层叠概念. css3为了区分伪类和伪元素,伪元素采用双冒号写法. 常见伪类——:hover,:link,:active,:targ ...

  4. 解决Windows下编辑脚本上传到Linux后遇到^M的方法

    Windows下编辑脚本上传到Linux后遇到^M,导致脚本无法执行,原因是因为Linux与Windows对 "回车键" 编码不同 解决方法如下: 在使用UE->文件-> ...

  5. SQL语句group by 与order by 执行顺序引发的一场“内斗”

    直入主题!看看下面这SQL会不会报错?如果报错应该是什么错误! --说明:黑色字体都是列SELECT application_id, index_num, num, amount FROM `cred ...

  6. python通过xlsxwriter模块将文字写入xlsx文件

    #今天和大家一起学习通过python的xlsxwriter模块 xlsxwriter模块主要用来生成excel表格,插入数据.插入图标等表格操作等. 环境:python 3 1)安装 xlsxwrit ...

  7. Ubuntu修改桌面为Desktop

    想用中文系统,却不想用中文文件夹,可以用以下方法: 先把home路径下的桌面文件夹修改为Desktop 然后在命令行输入 nano ~/.config/user-dirs.dirs 修改后ctrl - ...

  8. jdbc之存储过程的调用和调用方法

    调用存储过程 调用存储过程的sql语句 {call 过程名称(参数列表)} conn = DbUtils.getConnection(); sql = "{call p_order_appr ...

  9. 【七】ab压测

    [任务7]ab压测 安装ab压测软件 命令:yum -y install httpd-tools 进行压力测试: 执行命令:ab -c 20 -n 5000 http://192.168.159.30 ...

  10. 《PHP基础全面总结》系列分享专栏

    <PHP基础全面总结>已整理成PDF文档,点击可直接下载至本地查阅https://www.webfalse.com/read/201777.html 文章 PHP基础之运算符的使用方法 P ...