Queue termination

Nevertheless I don’t think we’re going to add that complication. If you don’t want to use the task_done() mechanism, bless your heart. Just ignore the count in the repr.

Based on @guido’s comment on how shutdown() should allow for draining of the remaining items in the queue and close() sounds like it should immediately make the object unusable, it seems like having both methods might be good instead of shutdown(immediate=True|False), which doesn’t seem to show up in many other APIs.

That’s an ornamental decision that I will leave to the community to make. For my use cases, I need the functionality from both options, but I’m not particular on the number of methods and parameters introduced

I think having both methods would be fine. BTW, @EpicWink, did you ever create that PR? I think you said there was an issue, but I don’t recall seeing a link to it. Maybe if you’re still distracted by real life, someone else could take over?

There was a period of when I had no time, with international travel and work projects, but since then the PR had just slipped my mind. Others are welcome to finish the PR, otherwise now that it’s on my mind I will look into it soon.

1 Like

What should occur if shutdown() is called multiple times (potentially with different values for immediate)? Looking through the PR implementation currently, it seems like it could be possible for a second call to unset the immediate state while threads are waiting, causing some threads to raise the shutdown exception while others continue to get() items until the queues are empty. Perhaps shutdown(immediate=False) should be a no-op if the state is shutdown-immediate already?

Yeah, I’d think the only allowed transitions would be from alive via shutdown to immediate.

Since this other queue improvements were mentioned in the idea topic I created yesterday, let me point back to it: queue.Queue - Adding Cancelling support - #8 by mementum

For some more inspiration the aio-pika rabbitmq client might be helpful. It has implementations for iterators as well as for callbacks
https://aio-pika.readthedocs.io/en/latest/rabbitmq-tutorial/1-introduction.html

Follow-on topic in ideas: Queue termination further

Asyncio queue shutdown will be in Python 3.13; see gh-96471: Add asyncio queue shutdown by EpicWink · Pull Request #104228 · python/cpython · GitHub

3 Likes