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: Queue.join(): Broken example in documentation
Type: Stage: resolved
Components: Documentation Versions: Python 3.7, Python 3.6, Python 3.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, misterunknown
Priority: normal Keywords:

Created on 2019-07-05 08:20 by misterunknown, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (2)
msg347310 - (view) Author: Marco Dickert (misterunknown) Date: 2019-07-05 08:20
I guess I found a bug in the documented Queue.join() example [1].

The problem is the break condition for the while loop of the worker. If the item is None, the loop breaks, but the worker never calls item.task_done(). Thus the q.join() statement never returns, because the last task (None) remains unfinished.

This should solve the issue:

```
if item is None:
  item.task_done()
  break
```

[1] https://docs.python.org/3/library/queue.html#queue.Queue.join
msg347311 - (view) Author: Marco Dickert (misterunknown) Date: 2019-07-05 08:31
Sorry, I missed that q.join() is executed *before* the "None" item is added to the queue.

In my real-world case I called q.join() *after* I added the "None" item.
History
Date User Action Args
2022-04-11 14:59:17adminsetgithub: 81684
2019-07-05 08:31:49misterunknownsetstatus: open -> closed
resolution: not a bug
messages: + msg347311

stage: resolved
2019-07-05 08:20:39misterunknowncreate