1import threading, queue
2
3q = queue.Queue()
4
5def worker():
6 while True:
7 item = q.get()
8 print(f'Working on {item}')
9 print(f'Finished {item}')
10 q.task_done()
11
12# turn-on the worker thread
13threading.Thread(target=worker, daemon=True).start()
14
15# send thirty task requests to the worker
16for item in range(30):
17 q.put(item)
18print('All task requests sent\n', end='')
19
20# block until all tasks are done
21q.join()
22print('All work completed')
23