In the Python Queue documentation, there is 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'm just wondering if this is the right approach, since it seems that the worker threads will never terminate. I think they'll become zombies in the end. Is it an issue that Python doc overlooked? Thanks.