[Python-ideas] Add closing and iteration to threading.Queue
hemflit at gmail.com
Sun Oct 21 15:19:21 EDT 2018
On Sun, Oct 21, 2018 at 8:45 PM MRAB <python at mrabarnett.plus.com> wrote:
> FTR, this has been discussed before:
> [Python-ideas] `__iter__` for queues?
For the sake of clarity, I want to outline a few differences between
that discussion and my proposal:
1. Much of the discussion there seemed to implicitly limit itself to
consideration of FIFO queues. This proposal works cleanly for child
classes too, including any (API-compliant) user-written children.
2. Throughout that discussion, iteration is the A feature, and closing
is occasionally mentioned as a possible prerequisite. In this
proposal, the A feature is closing, which enables sensible iteration
(as a B feature) but is useful even if iteration isn't used.
3. There's naturally a lot of quick spitballing of various
mutually-incompatible ideas there, whereas this is one rounded
self-consistent proposal. Most of what I've come up with has already
been anticipated there but it's all mixed up textually.
4. This proposal sidesteps a lot of the doubts and difficulties by
just not using sentinels at all. Being closed is part of the queue's
state that can be queried at any time, and will affect put() calls
immediately, without waiting for a sentinel to float up to the front.
(With recognition that your (MRAB's) message towards that thread's end
already proposed the same approach.)
More information about the Python-ideas