2. Use Queue.shutdown instead of sentinel values

In Python 3.13 and later, prefer Queue.shutdown() over inventing sentinel values to stop worker threads.

A dedicated shutdown API separates lifecycle signaling from the data values traveling through the queue. That removes the need to reserve special sentinel values and makes worker termination rules clearer.

Note

Python 3.13+

2.1. Don’t do this

 1import queue
 2
 3q = queue.Queue()
 4
 5q.put(task_1)
 6q.put(None)
 7
 8item = q.get()
 9if item is None:
10    return

2.2. Do this

1import queue
2
3q = queue.Queue()
4
5q.put(task_1)
6q.shutdown()