[python] Queue.Queue vs. collections.deque
https://stackoverflow.com/questions/717148/queue-queue-vs-collections-deque/717199#717199
Queue,Queue 用于多线程之间,无需lock的通信;
SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。collections.deque 用于实现数据结构中的queue, 或两端都可以实现queue的功能。
Queue.Queueandcollections.dequeserve different purposes. Queue.Queue is intended for allowing different threads to communicate using queued messages/data, whereascollections.dequeis simply intended as a datastructure. That's whyQueue.Queuehas methods likeput_nowait(),get_nowait(), andjoin(), whereascollections.dequedoesn't.Queue.Queueisn't intended to be used as a collection, which is why it lacks the likes of theinoperator.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, usecollections.deque.Finally, accessing and manipulating the internal deque of a
Queue.Queueis playing with fire - you really don't want to be doing that.

