# Queue termination

**URL:** <https://discuss.python.org/t/queue-termination/18386>\
**Category:** Async-SIG\
**Created:** [August 22, 2022, 4:11am UTC](https://discuss.python.org/t/queue-termination/18386 "2022-08-22T04:11:09Z")\
**Posts on this page:** 11\
**Page:** 3

<div class="post-metadata">

**Author:** ![guido](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/guido/32/21_2.png) [@guido](https://discuss.python.org/u/guido)\
**Post date:** [September 27, 2022, 5:10pm UTC](https://discuss.python.org/t/queue-termination/18386/41 "2022-09-27T17:10:40Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ConnorSMaynes](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/connorsmaynes/32/10002_2.png) [@ConnorSMaynes](https://discuss.python.org/u/ConnorSMaynes)\
**Post date:** [November 30, 2022, 1:34am UTC](https://discuss.python.org/t/queue-termination/18386/42 "2022-11-30T01:34:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![EpicWink](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/epicwink/32/17968_2.png) [@EpicWink](https://discuss.python.org/u/EpicWink)\
**Post date:** [November 30, 2022, 9:18pm UTC](https://discuss.python.org/t/queue-termination/18386/43 "2022-11-30T21:18:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![guido](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/guido/32/21_2.png) [@guido](https://discuss.python.org/u/guido)\
**Post date:** [November 30, 2022, 10:34pm UTC](https://discuss.python.org/t/queue-termination/18386/44 "2022-11-30T22:34:14Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![EpicWink](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/epicwink/32/17968_2.png) [@EpicWink](https://discuss.python.org/u/EpicWink)\
**Post date:** [November 30, 2022, 10:51pm UTC](https://discuss.python.org/t/queue-termination/18386/45 "2022-11-30T22:51:33Z")

</div>

> <https://github.com/python/cpython/pull/96474>
>
> \* Issue: gh-96471

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.

---

<div class="post-metadata">

**Author:** ![TeamSpen210](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/teamspen210/32/1004_2.png) [@TeamSpen210](https://discuss.python.org/u/TeamSpen210)\
**Post date:** [December 1, 2022, 2:43am UTC](https://discuss.python.org/t/queue-termination/18386/46 "2022-12-01T02:43:36Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![guido](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/guido/32/21_2.png) [@guido](https://discuss.python.org/u/guido)\
**Post date:** [December 1, 2022, 6:08am UTC](https://discuss.python.org/t/queue-termination/18386/47 "2022-12-01T06:08:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mementum](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/mementum/32/11696_2.png) [@mementum](https://discuss.python.org/u/mementum)\
**Post date:** [March 24, 2023, 9:20am UTC](https://discuss.python.org/t/queue-termination/18386/48 "2023-03-24T09:20:03Z")

</div>

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](https://discuss.python.org/t/queue-queue-adding-cancelling-support/25123/8)

---

<div class="post-metadata">

**Author:** ![Henkhogan](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/henkhogan/32/9913_2.png) [@Henkhogan](https://discuss.python.org/u/Henkhogan)\
**Post date:** [April 21, 2023, 9:34pm UTC](https://discuss.python.org/t/queue-termination/18386/49 "2023-04-21T21:34:17Z")

</div>

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](https://aio-pika.readthedocs.io/en/latest/rabbitmq-tutorial/1-introduction.html)

---

<div class="post-metadata">

**Author:** ![EpicWink](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/epicwink/32/17968_2.png) [@EpicWink](https://discuss.python.org/u/EpicWink)\
**Post date:** [May 10, 2023, 4:26am UTC](https://discuss.python.org/t/queue-termination/18386/50 "2023-05-10T04:26:46Z")

</div>

Follow-on topic in ideas: [Queue termination further](https://discuss.python.org/t/queue-termination-further/26630)

---

<div class="post-metadata">

**Author:** ![EpicWink](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/epicwink/32/17968_2.png) [@EpicWink](https://discuss.python.org/u/EpicWink)\
**Post date:** [April 8, 2024, 5:39am UTC](https://discuss.python.org/t/queue-termination/18386/51 "2024-04-08T05:39:23Z")

</div>

Asyncio queue shutdown will be in Python 3.13; see [gh-96471: Add asyncio queue shutdown by EpicWink · Pull Request #104228 · python/cpython · GitHub](https://github.com/python/cpython/pull/104228)

[Previous page](https://discuss.python.org/t/queue-termination/18386.md?page=2)
