[issue12155] queue example doesn't stop worker threads
New submission from STINNER Victor
Changes by Antoine Pitrou
Changes by Raymond Hettinger
Raymond Hettinger
It doesn't define do_work(), num_worker_threads or do_work()
Is it unclear to you what those mean? They are placeholders for the user's actual task at hand.
my concern is that it doesn't stop worker threads.
Stopping the threads wasn't the intent of the example.
I consider "t.daemon = True" as an hack to not care about stopping threads.
If you post a high-quality self-contained example somewhere on the net, I would be happy to link to it.
----------
priority: normal -> low
_______________________________________
Python tracker
STINNER Victor
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
Terry J. Reedy
Roundup Robot added the comment:
New changeset b44ec269abda by Victor Stinner in branch 'default':
Issue #12155: Fix queue doc example to join threads
https://hg.python.org/cpython/rev/b44ec269abda
----------
nosy: +python-dev
_______________________________________
Python tracker
Changes by STINNER Victor
participants (5)
-
Antoine Pitrou
-
Raymond Hettinger
-
Roundup Robot
-
STINNER Victor
-
Terry J. Reedy