Python: properly terminate worker threads
<p>In the Python <a href="https://docs.python.org/2/library/queue.html#Queue.Queue.join" rel="nofollow">Queue documentation</a>, there is the following example:</p>

<pre><code>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
</code></pre>

<p>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.</p>