Message367333
I'm thinking of simplifying the example to focus on its core goal of demonstrating how to enqueue tasks and then wait for them to be finished:
import threading, queue
q = queue.Queue()
def worker():
while True:
item = q.get()
print(f'Working on {item}')
print(f'Finished {item}')
q.task_done()
# turn-on the worker thread
worker_thread = threading.Thread(target=worker)
worker_thread.daemon = True
worker_thread.start()
# send thirty task requests to the worker
for item in range(30):
q.put(item)
print('All task requests sent\n', end='')
# block until all tasks are done
q.join()
print('All work completed') |
|
| Date |
User |
Action |
Args |
| 2020-04-26 23:29:34 | rhettinger | set | recipients:
+ rhettinger, docs@python, python-dev, remi.lapeyre, Santiago Blanco |
| 2020-04-26 23:29:34 | rhettinger | set | messageid: <[email protected]> |
| 2020-04-26 23:29:34 | rhettinger | link | issue40387 messages |
| 2020-04-26 23:29:34 | rhettinger | create | |
|