The official documentation here gives the following example:
def worker():
while True:
item = q.get()
do_work(item)
q.task_done()
q = Queue()
for i in range(num_worker_threads):
t = Thread(target=worker)
t.daemon = True
t.start()
for item in source():
q.put(item)
q.join() # block until all tasks are done
I want to make sure all the threads are killed at this point before my main thread proceeds. I suppose after all the tasks in the queue have been processed, the q.get() method will raise an exception, which should kill the thread. Is that correct?