Title: Queue.join(): Broken example in documentation
Type: Stage: resolved
Components: Documentation Versions: Python 3.7, Python 3.6, Python 3.5
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 2019-07-05 08:31 by misterunknown. 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:

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.
Date User Action Args
2019-07-05 08:31:49misterunknownsetstatus: open -> closed
resolution: not a bug
messages: + msg347311

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