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
🌐
Python
docs.python.org › 3 › library › queue.html
queue — A synchronized queue class
February 23, 2026 - Source code: Lib/queue.py The queue module implements multi-producer, multi-consumer queues. It is especially useful in threaded programming when information must be exchanged safely between multip...
🌐
GeeksforGeeks
geeksforgeeks.org › python › queue-in-python
Queue in Python - GeeksforGeeks
December 11, 2025 - Queue is a linear data structure that stores items in a First In First Out (FIFO) manner. The item that is added first will be removed first.
🌐
Medium
basillica.medium.com › working-with-queues-in-python-a-complete-guide-aa112d310542
Working with Queues in Python — A Complete Guide | by Basillica | Medium
March 27, 2024 - Queues are a useful data structure in programming that allow you to add and remove elements in a first in, first out (FIFO) order. Python provides a built-in module called queue that implements different types of queue data structures.
🌐
W3Schools
w3schools.com › python › ref_module_queue.asp
Python queue Module
Python Examples Python Compiler ... Python Certificate Python Training ... The queue module provides synchronized queue classes for multi-producer, multi-consumer scenarios....
Top answer
1 of 7
429

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
🌐
Real Python
realpython.com › ref › stdlib › queue
queue | Python Standard Library – Real Python
The Python queue module provides reliable thread-safe implementations of the queue data structure.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-queue-lifoqueue-vs-collections-deque
Python - Queue.LIFOQueue vs Collections.Deque - GeeksforGeeks
July 23, 2025 - in Python. queue.LifoQueue: The module queue provides a LIFO Queue which technically works as a Stack.
Find elsewhere
🌐
GitHub
github.com › python › cpython › blob › main › Lib › queue.py
cpython/Lib/queue.py at main · python/cpython
'''Simple, unbounded FIFO queue. · This pure Python implementation is not reentrant. ''' # Note: while this pure Python version provides fairness · # (by using a threading.Semaphore which is itself fair, being based · # on threading.Condition), fairness is not part of the API contract.
Author   python
🌐
Great Learning
mygreatlearning.com › blog › it/software development › python queue
Python Queue
October 14, 2024 - It will process the tasks in a manner called “First In First Out” which means the first process or task in the queue will be executed and removed first, after that other processes will be started. A queue can be implemented in programming languages such as Python, Java, C++, etc.
🌐
W3Schools
w3schools.com › python › python_dsa_queues.asp
Queues with Python
Since Python lists has good support for functionality needed to implement queues, we start with creating a queue and do queue operations with just a few lines:
🌐
Readthedocs
pydoc-zh.readthedocs.io › en › latest › library › queue.html
8.10. Queue — A synchronized queue class — Python 2.7.6 documentation
The module implements three types of queue, which differ only in the order in which the entries are retrieved. In a FIFO queue, the first tasks added are the first retrieved. In a LIFO queue, the most recently added entry is the first retrieved (operating like a stack).
🌐
Code Without Rules
codewithoutrules.com › 2017 › 08 › 16 › concurrency-python
The tragic tale of the deadlocking Python queue
August 16, 2017 - A common pattern is to create log messages in your application thread or threads, and do the actual writing to disk in a different thread. The easiest way to communicate the messages is, of course, a queue.Queue. This use case is in fact directly supported by the Python standard library:
🌐
Wondershare EdrawMax
edrawmax.wondershare.com › home › for it service › implementing a queue in python: step-by-step tutorial
Implementing Queues in Python: A Comprehensive Guide
October 22, 2025 - Queues have a wide range of applications such as operating system task scheduling, breadth-first search algorithms, and more. In Python, queues can be implemented easily using built-in data structures like lists or collections dequeue.
🌐
Software Testing Help
softwaretestinghelp.com › home › python programming for beginners – free python tutorials › python queue tutorial: how to implement and use python queue
Python Queue Tutorial: How To Implement And Use Python Queue
April 1, 2025 - To delete the element in the queue the “ get() ” function is used. It is known as the dequeue operation. The Python queue works on the FIFO ( First In First Out ) principle i.e.
Top answer
1 of 1
1

It's unclear what you mean by "Queue". The only two standard Queue implementations I'm aware of cannot be iterated over, so "casting it as a list" just raises an exception:

>>> import queue
>>> q = queue.Queue()
>>> list(q)
Traceback (most recent call last):
    ...
TypeError: 'Queue' object is not iterable

>>> from multiprocessing import Queue
>>> q = Queue()
>>> list(q)
Traceback (most recent call last):
    ...
TypeError: 'Queue' object is not ierable

Whether you may ever need to do:

with lock_object:
    some_function(queue)

can't be answered based on what you've said so far. If, for example, your higher-level logic relies on putting the queue into (in effect) "read only" mode for some time, then, sure. You'll need a lock to ensure mutual exclusion between the reading and writing sides for the duration.

.put() and .get() on their own are already thread- and process- (in the case of multiprocessing.Queue) safe.

More than just that is not guaranteed by the docs, so can't be relied on even if it "appears to" work (which, if so, may be a reliable accident of the specific Python implementation you're using, or may be a fickle accident due to your simply not having yet bumped into a relevant race condition).

NEW QUESTION, NEW ANSWER

The question was edited to ask about list(queue.queue) instead. That falls under the earlier "accident of the specific Python implementation you're using", in two respects:

  1. It's not documented that a Queue.queue object has a queue attribute. Python is a "consenting adults" language, and doesn't try to prevent you from using implementation details. But, if you do, you're on your own. The implementation may change at any time.
  2. It so happens that list(deque) is thread-safe today (CPython 3.12.5), but that's not documented either. I only know that it is because I stared at the C implementation code. It may not be thread-safe in 3.12.6. More generally, CPython is moving toward a "no GIL" mode of operation, in which this kind of thing becomes much more likely to suffer races.

The bottom line doesn't change: .put() and .get() on their own are already thread- and process- (in the case of multiprocessing.Queue) safe. Nothing more than that is guaranteed. Really! ;-) Nothing. If you need more than just that much to be reliable across implementations and releases, you'll need to supply your own locks.

🌐
Troy Fawkes
troyfawkes.com › home › blog › the basics of python multithreading and queues
The Basics of Python Multithreading and Queues - Troy Fawkes
May 13, 2024 - The second visual difference is the task_done() bit at the end. That tells the queue that not only have I retrieved the information from the list, but I’ve finished with it. If I don’t call task_done() then I run into trouble in threading.
🌐
Beautiful Soup
tedboy.github.io › python_stdlib › generated › generated › multiprocessing.Queue.html
multiprocessing.Queue() — Python Standard Library
Docs » · api » · multiprocessing » · multiprocessing.Queue() · View page source · multiprocessing · Queue · (maxsize=0)[source]¶ · Returns a queue object
🌐
Python Module of the Week
pymotw.com › 2 › Queue
Queue – A thread-safe FIFO implementation - Python Module of the Week
Now available for Python 3! Buy the book! ... The Queue module provides a FIFO implementation suitable for multi-threaded programming. It can be used to pass messages or other data between producer and consumer threads safely. Locking is handled for the caller, so it is simple to have as many ...
🌐
TutorialsPoint
tutorialspoint.com › stack-and-queue-in-python-using-queue-module
Stack and Queue in Python using queue Module
July 30, 2019 - The Queue module implements multi-producer, multi-consumer queues and It is especially useful in threaded programming when information must be exchanged safely between multiple threads. The Queue class in this module implements all the required locking semantics and it depends on the availability ...