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.

Author hemflit
Recipients hemflit
Date 2018-10-20.23:29:15
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1540078155.51.0.788709270274.issue35034@psf.upfronthosting.co.za>
In-reply-to
Content
Code using threading.Queue often needs to coordinate a "work is finished as far as far as I care" state between the producing and consuming side.

When going from the producer to the consumer ("No more items after this, so don't bother waiting"), this is usually implemented with sentinel objects, which is at best needlessly verbose and at worst tricky to get right (as with multiple consumers, or communicating a non-trivial sentinel object).
When going the other direction ("I'm not interested in consuming any more, so you can stop putting them on the queue"), or when a third component needs to notify both sides ("You two start wrapping up, but don't drop any in-flight items") there isn't even a clear usual solution.

Adding a close() method to the Queue (with accompanying exception treatment etc.) would solve all of this in a very clean way. It would not change anything for code that doesn't want to use it. It would simplify a lot of everyday uses of Queue. Many simple producers could reduce their coordination code to a `with closing(queue)` idiom. A further __iter__() method would enable many simple consumers to safely cut all their coordination boilerplate down to just `for item in queue`.

I've got a sample implementation ready for Queue and its children, and I'm about to submit it as a PR.

I'd be happy to contribute an equivalent (within limits of its API promises) implementation for SimpleQueue, but I don't have it written, and I'm unsure if I should make a separate issue for that.
History
Date User Action Args
2018-10-20 23:29:15hemflitsetrecipients: + hemflit
2018-10-20 23:29:15hemflitsetmessageid: <1540078155.51.0.788709270274.issue35034@psf.upfronthosting.co.za>
2018-10-20 23:29:15hemflitlinkissue35034 messages
2018-10-20 23:29:15hemflitcreate