This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Broken example in the queue module documentation
Type: behavior Stage: resolved
Components: Documentation Versions: Python 3.6, Python 3.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Paulo Gabriel Poiati, docs@python, r.david.murray
Priority: normal Keywords:

Created on 2016-08-12 14:01 by Paulo Gabriel Poiati, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg272540 - (view) Author: Paulo Gabriel Poiati (Paulo Gabriel Poiati) Date: 2016-08-12 14:01
I believe the code example at https://docs.python.org/3.6/library/queue.html is broken. The break condition in the worker loop (when the queued value is None) must call the `task_done` before breaking, otherwise the code blocks indefinitely in the `queue.join()` statement.
msg272542 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2016-08-12 14:42
The example looks correct to me.  Have you tested it and seen it hang?

The q.join() is done, and returns once all the puts have been processed.  *Then* None is put for each worker, which terminates the worker thread.  There's no q.join() to block at that point.
msg272547 - (view) Author: Paulo Gabriel Poiati (Paulo Gabriel Poiati) Date: 2016-08-12 17:24
You are absolutely right David. I was calling join after putting `None` in the queue. Sorry, I'm closing this.
History
Date User Action Args
2022-04-11 14:58:34adminsetgithub: 71934
2016-08-12 18:17:31r.david.murraysettype: enhancement -> behavior
stage: resolved
2016-08-12 17:24:36Paulo Gabriel Poiatisetstatus: open -> closed
resolution: not a bug
messages: + msg272547
2016-08-12 14:42:52r.david.murraysetnosy: + r.david.murray
messages: + msg272542
2016-08-12 14:01:01Paulo Gabriel Poiaticreate