Am I interpreting that right?

You observe such behavior because you’re modifying the same object all the time

Lets put aside queues / threads and run a simplified equivalent of your code with some prints to understand what’s happening

t = {}
l = []
for i in range(3):
    t['a'] = i
    l.append(t)
print(l)
t['a'] = 20
print(l)
print(map(id, l))

[{'a': 2}, {'a': 2}, {'a': 2}]
[{'a': 20}, {'a': 20}, {'a': 20}]
# they are all the same!
[4474861840, 4474861840, 4474861840]

So it has nothing to do we threads/queues - you’re just adding the same object 3 times.

Now, if I move the instantiation of the dictionary inside the for loop

In this case you create a new object every time like in the following code:

l = []
for i in range(3):
    t = {}
    t['a'] = i
    l.append(t)
print(l)
t['a'] = 20
print(l)
print(map(id, l))

[{'a': 0}, {'a': 1}, {'a': 2}]
[{'a': 0}, {'a': 1}, {'a': 20}]
# they are all different!
[4533475600, 4533502592, 4533502872]

So no magic here

back to your question

This is what could be of interest for you: “Is python’s queue.Queue.put() thread safe?” meaning that the global variable q could be accessed by multiple concurrent threads safely. The answer is yes - it is thread safe

The Queue module implements multi-producer, multi-consumer queues. 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

Answer from Oleg Kuralenko on Stack Overflow
🌐
Python
docs.python.org › 3 › library › queue.html
queue — A synchronized queue class
February 23, 2026 - Put item into the queue. If optional args block is true and timeout is None (the default), block if necessary until a free slot is available. If timeout is a positive number, it blocks at most timeout seconds and raises the Full exception if no free slot was available within that time.
🌐
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. It is commonly used for task scheduling and managing work between multiple threads.
🌐
GeeksforGeeks
geeksforgeeks.org › python › queue-in-python
Queue in Python - GeeksforGeeks
December 11, 2025 - Key Methods are: put(item) / put_nowait(item) – Add an element. get() / get_nowait() – Remove an element. empty() – Check if the queue is empty. full() – Check if the queue is full.
🌐
Python Module of the Week
pymotw.com › 2 › Queue
Queue – A thread-safe FIFO implementation - Python Module of the Week
import Queue class Job(object): def __init__(self, priority, description): self.priority = priority self.description = description print 'New job:', description return def __cmp__(self, other): return cmp(self.priority, other.priority) q = Queue.PriorityQueue() q.put( Job(3, 'Mid-level job') ) q.put( Job(10, 'Low-level job') ) q.put( Job(1, 'Important job') ) while not q.empty(): next_job = q.get() print 'Processing job:', next_job.description · In this single-threaded example, the jobs are pulled out of the queue in strictly priority order. If there were multiple threads consuming the jobs, they would be processed based on the priority of items in the queue at the time get() was called. $ python Queue_priority.py New job: Mid-level job New job: Low-level job New job: Important job Processing job: Important job Processing job: Mid-level job Processing job: Low-level job
🌐
Python
docs.python.org › 3 › library › asyncio-queue.html
Queues — Python 3.14.4 documentation
February 22, 2026 - The count goes down whenever a consumer coroutine calls task_done() to indicate that the item was retrieved and all work on it is complete. When the count of unfinished tasks drops to zero, join() unblocks. ... Put an item into the queue.
🌐
Pythontic
pythontic.com › queue-module › queue-class › put
The put() method of Queue class in Python | Pythontic.com
The method put() adds an element to an instance of Queue class while the instance has not reached its maximum capacity. If the queue is full the put() method blocks till an element is removed, typically by another thread with which the Queue instance is shared.
🌐
Great Learning
mygreatlearning.com › blog › it/software development › python queue
Python Queue
October 14, 2024 - When there is no element in the queue, it waits for the element to be available in the queue. put(): This method is used to add an element in the queue which can be represented as an instance of Queue.
🌐
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.
Find elsewhere
Top answer
1 of 2
3

Am I interpreting that right?

You observe such behavior because you’re modifying the same object all the time

Lets put aside queues / threads and run a simplified equivalent of your code with some prints to understand what’s happening

t = {}
l = []
for i in range(3):
    t['a'] = i
    l.append(t)
print(l)
t['a'] = 20
print(l)
print(map(id, l))

[{'a': 2}, {'a': 2}, {'a': 2}]
[{'a': 20}, {'a': 20}, {'a': 20}]
# they are all the same!
[4474861840, 4474861840, 4474861840]

So it has nothing to do we threads/queues - you’re just adding the same object 3 times.

Now, if I move the instantiation of the dictionary inside the for loop

In this case you create a new object every time like in the following code:

l = []
for i in range(3):
    t = {}
    t['a'] = i
    l.append(t)
print(l)
t['a'] = 20
print(l)
print(map(id, l))

[{'a': 0}, {'a': 1}, {'a': 2}]
[{'a': 0}, {'a': 1}, {'a': 20}]
# they are all different!
[4533475600, 4533502592, 4533502872]

So no magic here

back to your question

This is what could be of interest for you: “Is python’s queue.Queue.put() thread safe?” meaning that the global variable q could be accessed by multiple concurrent threads safely. The answer is yes - it is thread safe

The Queue module implements multi-producer, multi-consumer queues. 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

2 of 2
2

In the first example, you are putting the same dict into the queue three times. This has nothing to do with the queue. You would find the same behaviour with list.append.

🌐
Readthedocs
pydoc-zh.readthedocs.io › en › latest › library › queue.html
8.10. Queue — A synchronized queue class — Python 2.7.6 documentation
Equivalent to put(item, False). ... Remove and return an item from the queue. If optional args block is true and timeout is None (the default), block if necessary until an item is available. If timeout is a positive number, it blocks at most timeout seconds and raises the Empty exception if no item was available within that time.
🌐
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
🌐
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.
🌐
SSOJet
ssojet.com › data-structures › implement-queue-in-python
Implement Queue in Python | Implement Data Structures in Programming Languages
Python's queue module provides a PriorityQueue class perfect for this. You'll store items as tuples, with the priority value as the first element, like (priority, item). ... import queue pq = queue.PriorityQueue() pq.put((2, "medium priority ...
🌐
Microsoft Learn
learn.microsoft.com › en-us › azure › storage › queues › storage-quickstart-queues-python
Quickstart: Azure Queue Storage client library for Python - Azure Storage | Microsoft Learn
June 29, 2023 - Learn how to use the Azure Queue Storage client library for Python to create a queue and add messages to it. Then learn how to read and delete messages from the queue. You also learn how to delete a queue.
🌐
Python
docs.python.org › 3.5 › library › asyncio-queue.html
18.5.8. Queues — Python 3.5.10 documentation
December 18, 2020 - If the queue is full, wait until a free slot is available before adding item. This method is a coroutine. ... The full() method. ... Put an item into the queue without blocking.
🌐
Python
docs.python.org › 3 › library › multiprocessing.html
multiprocessing — Process-based parallelism
February 23, 2026 - Returns a process shared queue implemented using a pipe and a few locks/semaphores. When a process first puts an item on the queue a feeder thread is started which transfers objects from a buffer into the pipe.
🌐
AskPython
askpython.com › home › python queue module
Python Queue Module - AskPython
February 26, 2020 - This is a part of the standard Python library, so there’s no need to use pip. Import the module using: import queue · To create a Queue object, we can instantiate it using: q = queue.Queue() By default, this has a capacity of 0, but if you want to explicitly mention it, you can do so using: q = queue.Queue(max_capacity) We can insert and retrieve values into the Queue using the queue.get() and queue.put() methods.
🌐
iO Flood
ioflood.com › blog › python-queue
Python Queue Class | Usage Guide (With Examples)
February 5, 2024 - Python’s queue module offers more than just the basic FIFO queue. It also provides other types of queues such as LifoQueue and PriorityQueue. LifoQueue, or Last-In-First-Out queue, operates as a stack where the last item added is the first one to be removed. Here’s an example: import queue # Create a LifoQueue lq = queue.LifoQueue() # Add items to the queue lq.put('Apple') lq.put('Banana') lq.put('Cherry') # Remove items from the queue print(lq.get()) # Output: 'Cherry' print(lq.get()) # Output: 'Banana' print(lq.get()) # Output: 'Apple'
🌐
W3Schools
w3schools.com › python › ref_module_queue.asp
Python queue Module
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Practice Problems Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training · ❮ Standard Library Modules · Create a FIFO queue, put an item, then get it back: import queue q = queue.Queue() q.put('task1') print(q.get()) Try it Yourself » ·
🌐
Intellipaat
intellipaat.com › home › blog › queue in python – implementation explained
Queue in Python: How to Implement Queue in Python
October 14, 2025 - A simple queue items are can be accessed in the First-in-First-out(FIFO). Let’s understand how to add or remove items from a LIFO queue. To add items in a queue, put() function is used.