๐ŸŒ
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.
๐ŸŒ
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.
๐ŸŒ
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....
๐ŸŒ
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
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_dsa_queues.asp
Queues with Python
Python Examples Python Compiler ... Bootcamp Python Certificate Python Training ... A queue is a linear data structure that follows the First-In-First-Out (FIFO) principle....
๐ŸŒ
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.
๐ŸŒ
Python
docs.python.org โ€บ 3 โ€บ library โ€บ asyncio-queue.html
Queues โ€” Python 3.14.4 documentation
February 22, 2026 - Source code: Lib/asyncio/queues.py asyncio queues are designed to be similar to classes of the queue module. Although asyncio queues are not thread-safe, they are designed to be used specifically i...
Find elsewhere
๐ŸŒ
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).
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
๐ŸŒ
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 ...
๐ŸŒ
Real Python
realpython.com โ€บ queue-in-python
Python Stacks, Queues, and Priority Queues in Practice โ€“ Real Python
December 1, 2023 - In this tutorial, you'll take a deep dive into the theory and practice of queues in programming. Along the way, you'll get to know the different types of queues, implement them, and then learn about the higher-level queues in Python's standard library. Be prepared to do a lot of coding.
๐ŸŒ
Simplilearn
simplilearn.com โ€บ home โ€บ resources โ€บ software development โ€บ queue in python: working with queue data structure in python
Queue in Python: Working With Queue Data Structure in Python
March 5, 2026 - A queue is a built-in module of python used in threaded programming. It stores items sequentially in a FIFO manner. Learn all about the queue in python now!
Address ย  5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
๐ŸŒ
AskPython
askpython.com โ€บ home โ€บ python queue module
Python Queue Module - AskPython
February 26, 2020 - A Queue is a data structure where ... where the first in line is also the first one out. In Python, we can use the queue module to create a queue of objects....
๐ŸŒ
Read the Docs
python.readthedocs.io โ€บ en โ€บ latest โ€บ library โ€บ queue.html
17.7. queue โ€” A synchronized queue class
November 15, 2017 - 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...
๐ŸŒ
BitDegree
bitdegree.org โ€บ learn โ€บ python-queue
The Four Types of Python Queue: Definitions and Examples
February 19, 2020 - TL;DR โ€“ A Python queue is a linear data structure, similar to a stack.
๐ŸŒ
Runestone Academy
runestone.academy โ€บ ns โ€บ books โ€บ published โ€บ pythonds โ€บ BasicDS โ€บ ImplementingaQueueinPython.html
4.12. Implementing a Queue in Python โ€” Problem Solving with Algorithms and Data Structures
We need to decide which end of the list to use as the rear and which to use as the front. The implementation shown in Listing 1 assumes that the rear is at position 0 in the list. This allows us to use the insert function on lists to add new elements to the rear of the queue.
๐ŸŒ
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.
๐ŸŒ
Intellipaat
intellipaat.com โ€บ home โ€บ blog โ€บ queue in python โ€“ implementation explained
Queue in Python: How to Implement Queue in Python
October 14, 2025 - This brings us to the end of this module in Python Tutorial. Now, if you want to know why Python is the preferred language for data science, you can go through this blog on Python Data Science tutorial. Queue is a collection of similar items arranged in a linear order.