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 data structure. 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 in operator.

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.

Answer from Keith Gaughan on Stack Overflow
Top answer
1 of 7
430

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 data structure. 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 in operator.

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.

2 of 7
64

If all you're looking for is a thread-safe way to transfer objects between threads, then both would work (both for FIFO and LIFO). For FIFO:

  • Queue.put() and Queue.get() are thread-safe
  • Deques support thread-safe, memory efficient appends and pops from either side of the deque with approximately the same O(1) performance in either direction.

Note:

  • Other operations on deque might not be thread safe, I'm not sure.
  • deque does not block on pop() or popleft() so you can't base your consumer thread flow on blocking till a new item arrives.

However, it seems that deque has a significant efficiency advantage. Here are some benchmark results in seconds using CPython 2.7.3 for inserting and removing 100k items

deque 0.0747888759791
Queue 1.60079066852

Here's the benchmark code:

import time
import Queue
import collections

q = collections.deque()
t0 = time.clock()
for i in xrange(100000):
    q.append(1)
for i in xrange(100000):
    q.popleft()
print 'deque', time.clock() - t0

q = Queue.Queue(200000)
t0 = time.clock()
for i in xrange(100000):
    q.put(1)
for i in xrange(100000):
    q.get()
print 'Queue', time.clock() - t0
🌐
GeeksforGeeks
geeksforgeeks.org › python › difference-between-queue-queue-vs-collections-deque-in-python
Difference between queue.queue vs collections.deque in Python - GeeksforGeeks
July 23, 2025 - We also know, that two threads may have to communicate with each other and this is where queue.queue comes into the picture. Collections.deque on the other hand is used as a data structure within a thread to perform certain functionality.
Discussions

Is there a good reason not to use deque when a queue will suffice?
Deque is a single threaded queue and is what you should use if you want a queue for something like BFS. Queue isn’t just a queue, it’s a specialized multi threading data structure that’s designed for communication between threads. Do not use Queue if you just want to do a simple single threaded BFS, it adds unnecessary overhead. In Python, the native implementation of a simple stack is a list and that of a simple queue is deque. More on reddit.com
🌐 r/learnpython
4
2
December 27, 2019
Normal Queue vs Lists?
As I understand, both list.pop(0) and dequeue.popleft() operate in O(1). This is incorrect, because as you note: when you pop(0) a list, it needs to move all the memory "to the side 1 space" so to speak. This means list.pop(0) operates in O(n). collections.deque will be far more efficient as a FIFO queue, though list is an efficient stack. More on reddit.com
🌐 r/learnpython
4
5
May 6, 2016
Is there a good reason not to use deque when a queue will ...
🌐 r/learnpython
Use deque instead of list always ?

The article mentions the advantages of deque, but neglects the mention its disadvantages. While deque has fast pop/append from both ends, it has slow item access.

Use deque only if you need insert/remove to be fast from both ends, and don't care about read speeds. List has constant time append/pop from one end and also constant time access anywhere in the list. You should almost always prefer list over deque, which is why list is builtin.

More on reddit.com
🌐 r/learnpython
8
13
December 28, 2017
🌐
Dataquest
dataquest.io › home › blog › python deque function: a better choice for queues and stacks
Python Deque Function: A Better Choice for Queues and Stacks – Dataquest
April 7, 2025 - If you use Python, you're probably familiar with lists, and you probably use them a lot, too. They're great data structures with many helpful methods that allow the user to modify the list by adding, removing, and sorting items. However, there are some use cases when a list may look like a great choice, but it just isn't. That is where the deque() function (short for double-ended queue, pronounced like "deck") from the collections module can be a much better choice when you need to implement queues and stacks in Python.
🌐
Career Karma
careerkarma.com › blog › python › python queue and deque: a step-by-step guide
Python Queue and Deque: A Step-By-Step Guide | Career Karma
December 1, 2023 - Python queue is a built in library that allows you to create a list that uses the FIFO rule, first in first out. Python deque uses the opposite rule, LIFO queue, or last in first out.
🌐
CodeSignal
codesignal.com › learn › courses › advanced-built-in-data-structures-and-their-usage › lessons › understanding-queues-and-deques-in-python
Understanding Queues and Deques in Python
A deque, or "double-ended queue", allows the addition and removal of items from both ends. Python provides the collections module containing the deque class for implementing deques.
🌐
Reddit
reddit.com › r/learnpython › is there a good reason not to use deque when a queue will suffice?
r/learnpython on Reddit: Is there a good reason not to use deque when a queue will suffice?
December 27, 2019 -

I recently learned about the deque class from collections in Python. I've been coding pretty haphazardly until now, not following any real design rules or anything, since I'm self taught and yprojects are for myself. Now I'm trying to tighten things up and bit and deciding if I should use a deque or queue to implement a command design pattern. Right now I see no particular need to append/pop from both sides but I'm tempted to use a deque just for the flexibility. Is there any reason I should stick with a 'single-end' plain queue?

🌐
Medium
medium.com › analytics-vidhya › queue-deque-overview-and-its-implementation-in-python-c36c56b532b8
Queue & Deque Overview and Its Implementation in Python | by Manikanth | Analytics Vidhya | Medium
January 7, 2021 - The enqueue term describes when we add a new item to the rare of the queue. Dequeue term describes removing the item from the front.
Find elsewhere
🌐
Real Python
realpython.com › python-deque
Python's deque: Implement Efficient Queues and Stacks – Real Python
January 12, 2026 - This data type was specially designed to overcome the efficiency problems of .append() and .pop() in Python lists. A deque is a sequence-like data structure designed as a generalization of stacks and queues.
🌐
CodingNomads
codingnomads.com › python-deque-for-python-queue-and-stack
Python Deque for Python Queue and Stack
You've swapped trade-offs between these two data structures. Because stacks are meant to retrieve items only from the end of the collection, deque is a more optimal implementation of this data structure in Python than a list. Queues also have a lot of use cases in programming.
🌐
PrepBytes
prepbytes.com › home › python › difference between queue.queue vs collections.deque in python
Python Difference Between Queue Vs Collections Deque in Python
August 30, 2022 - Let's go ahead and utilize a queue along with its operations in python language using the deque class! The deque class is imported from the collections module.
🌐
Reddit
reddit.com › r/learnpython › normal queue vs lists?
r/learnpython on Reddit: Normal Queue vs Lists?
May 6, 2016 -

Reading the code on a Queue

queue.Queue

This just seems like a fancy list initialized as a dequeue which only .get()s the first item of a list.

As I understand, both list.pop(0) and dequeue.popleft() operate in O(1).

The only difference that I notice is that when you pop(0) a list, it needs to move all the memory "to the side 1 space" so to speak. Is this the only real difference between dequeues and lists?

Should I just use a list as a FIFO, or is a list better for LIFO\Stack?

🌐
Stack Abuse
stackabuse.com › guide-to-queues-in-python
Guide to Queues in Python
April 18, 2024 - Your choice of queue implementation ... performance, collections.deque is a compelling choice. However, for multi-threaded applications or when priorities come into play, the queue module offers robust solutions....
🌐
Fanyang Meng's Blog
fanyangmeng.blog › fundamentals-of-stacks-and-queues
Fundamentals of Stacks and Queues - Fanyang Meng's Blog
January 8, 2025 - ... While list can serve as a stack, collections.deque is preferred for high-performance stack operations because it is optimized for fast append and pop operations from both ends.
🌐
Note.nkmk.me
note.nkmk.me › home › python
How to Use Deque in Python: collections.deque | note.nkmk.me
April 20, 2025 - Indexed access is O(1) at both ends but slows to O(n) in the middle. For fast random access, use lists instead. collections - deque objects — Container datatypes — Python 3.13.3 documentation ... It’s best to use deque when you specifically need to handle data as a queue, stack, or double-ended queue.
🌐
Quora
quora.com › What-are-the-pros-and-cons-of-a-list-versus-a-deque-in-Python-Under-what-conditions-should-we-use-a-list-versus-a-deque
What are the pros and cons of a list versus a deque in Python? Under what conditions should we use a list versus a deque? - Quora
The deque is the best choice for a FIFO queue abstraction. A LIFO stack abstraction can often be handled adequately by a resizable array. Data requirements that somehow combine the two are best handled with a deque. ... RelatedWhat are the advantages and disadvantages of using list comprehensions over for loops in Python...
🌐
Real Python
realpython.com › queue-in-python
Python Stacks, Queues, and Priority Queues in Practice – Real Python
December 1, 2023 - As you already know by now, a deque or double-ended queue satisfies those requirements. Plus, it’s universal enough to adapt for a LIFO queue as well. However, because coding one would be out of scope of this tutorial, you’re going to leverage Python’s deque collection from the standard library.
🌐
TutorialsPoint
tutorialspoint.com › queue-lifoqueue-vs-collections-deque-in-python
Queue.LIFOQueue vs Collections.Deque in Python
October 3, 2023 - Deque: deque(['Banana', 'Apple', 'Guava', 'Litchi']) Removed from left: Banana Removed from right: Litchi Updated deque: deque(['Apple', 'Guava']) Deque length: 2 ... Choose Queue.LIFOQueue for thread-safe stack operations with blocking capabilities. Use collections.deque for high-performance double-ended operations in single-threaded scenarios.
🌐
Medium
medium.com › cloud-for-everybody › stop-using-lists-for-queues-and-stacks-in-python-use-deque-instead-7c9619802ca0
Stop Using Lists for Queues in Python: Use Deque Instead
March 1, 2026 - They’ll think something like, “I’ll just use insert(0, item) and pop(0) — that should work as a queue, right?” · But here’s the catch: inserting an item at the beginning of a list using insert(0, item) takes O(n) time because all other elements have to be shifted one position to the right. And the same goes for pop(0), which also requires shifting elements. That’s why these operations get slower as your list grows longer. This is exactly where a deque comes in. In this tutorial, we’ll explore what a Python deque is, how it's different from a list, and how you can use it…
🌐
GeeksforGeeks
geeksforgeeks.org › deque-in-python
Deque in Python - GeeksforGeeks
Unlike regular queues, which are typically operated on using FIFO (First In, First Out) principles, a deque supports both FIFO and LIFO (Last In, First Out) operations. ... Input Restricted Deque: Input is limited at one end while deletion is ...
Published   March 6, 2025