zoukankan      html  css  js  c++  java
  • [python] Queue.Queue vs. collections.deque

    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.

  • 相关阅读:
    ssh 命令
    mtr 命令
    ping 命令
    curl 命令
    echo 命令
    cp 命令
    sftp服务器配置
    tomcat性能优化
    消息队列
    深度学习
  • 原文地址:https://www.cnblogs.com/shiyublog/p/10760375.html
Copyright © 2011-2022 走看看