mirror of
https://github.com/python/cpython.git
synced 2025-11-11 06:39:54 +00:00
Remove print race from task_done example. (GH-31795)
This commit is contained in:
parent
7854012077
commit
a0eb69c1a2
1 changed files with 3 additions and 4 deletions
|
|
@ -201,15 +201,14 @@ Example of how to wait for enqueued tasks to be completed::
|
||||||
print(f'Finished {item}')
|
print(f'Finished {item}')
|
||||||
q.task_done()
|
q.task_done()
|
||||||
|
|
||||||
# turn-on the worker thread
|
# Turn-on the worker thread.
|
||||||
threading.Thread(target=worker, daemon=True).start()
|
threading.Thread(target=worker, daemon=True).start()
|
||||||
|
|
||||||
# send thirty task requests to the worker
|
# Send thirty task requests to the worker.
|
||||||
for item in range(30):
|
for item in range(30):
|
||||||
q.put(item)
|
q.put(item)
|
||||||
print('All task requests sent\n', end='')
|
|
||||||
|
|
||||||
# block until all tasks are done
|
# Block until all tasks are done.
|
||||||
q.join()
|
q.join()
|
||||||
print('All work completed')
|
print('All work completed')
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue