⚡ Concurrency & Parallelism
Producer / Consumer with Queue
Thread-safe coordination with queue.Queue.
queue.Queue is the canonical way to hand work between threads safely.
import queue, threading
q = queue.Queue()
def consumer():
while True:
item = q.get()
if item is None: break
print("got", item)
q.task_done()