[docs] [issue12155] queue example doesn't stop worker threads

STINNER Victor report at bugs.python.org
Tue May 24 09:32:37 CEST 2011


STINNER Victor <victor.stinner at haypocalc.com> added the comment:

> Is it unclear to you what those mean?

Well, it's clear, but I like when I can simply copy/paste the example and it does just work:

> If you post a high-quality self-contained example somewhere 
> on the net, I would be happy to link to it.

I just propose to change the example to stop the threads:
------------------
def worker():
    while True:
        item = q.get()
        if item is None:
            break
        do_work(item)
        q.task_done()

q = Queue()
threads = []
for i in range(num_worker_threads):
     t = Thread(target=worker)
     threads.append(t)
     t.start()

for item in source():
    q.put(item)

q.join()       # block until all tasks are done
for i in range(num_worker_threads):
    q.put(None)
for t in threads: t.join()
------------------

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12155>
_______________________________________


More information about the docs mailing list