Skip to content

Queue shutdown #96471

Open
Open

Description

@EpicWink

Add a shutdown method to queue class (threading queue, multiprocessing, asyncio) which causes all future puts to raise (a queue.QueueShutdown) and all future gets once the queue is empty to also raise, unblocking all waiters. An optional argument immediate=True will skip the requirement for the queue to be empty.

This will enable producers and consumers to use the queue to know when to stop. This is important because both producers and consumers can be blocked waiting on the queue.

Previous discussion:

Linked PRs

Activity

  1. added a commit that references this issue on Feb 25, 2024
  2. added a commit that references this issue on Mar 4, 2024
  3. added a commit that references this issue on Mar 13, 2024
  4. added a commit that references this issue on Mar 20, 2024
  5. added a commit that references this issue on Mar 25, 2024
  6. EpicWink commented on Mar 28, 2024

    @EpicWink
    ContributorAuthor

    @ericsnowcurrently I'm not familiar with subinterpreters. Is the subinterpreter queue compatible with this new API?

  7. ericsnowcurrently commented on Mar 28, 2024

    @ericsnowcurrently
    Member

    Yeah, add shutdown to interpreter queues shouldn't be a problem. Basically, Queue.shutdown() would result in setting a flag on the runtime-global queue data, which would then be reflected by calls to Queue.put() and Queue.get().

  8. added 2 commits that reference this issue on Apr 6, 2024
  9. added 4 commits that reference this issue on Apr 17, 2024
  10. added a commit that references this issue on Jan 22, 2025
  11. Jean-Luc-Picard-2021 commented on Aug 18, 2026

    @Jean-Luc-Picard-2021

    Would it be possibly to add "shutdown" also to Threading.join etc..
    Basically replicating the exception signature throws InterruptedException
    from Java. Or what is the Pythonesk approach to get out of Threading.join ?

    Similarly for Semaphores. Basically extending the concept introduced
    here from Queues, to other concurrency elements such as the more
    simpler Semaphores and even Threads itself. BTW: Didn't check whether

    my feature request has a duplicate and whether this is the right place.

  12. gvanrossum commented on Aug 18, 2026

    @gvanrossum
    Member

    @Jean-Luc-Picard-2021 Please start a discussion on Discord if you want your suggestion to be heard.

  13. Jean-Luc-Picard-2021 commented on Aug 21, 2026

    @Jean-Luc-Picard-2021

    Thx, I have 99 problems but not getting heard is none of mine.
    Proof: See comment above from former BDFL himself.
    But it would be more helpful to hint why I should move

    to discord. Does Python not anymore use GitHub, Discourse, etc..?
    BTW: I don't have a Discord account, because of social media
    inflation, and sometimes ticket systems and not discussions are

    used for feature requests and/or roadmaps. Because of cohesion.

  14. EpicWink commented on Aug 21, 2026

    @EpicWink
    ContributorAuthor

    Does Python not anymore use GitHub

    @Jean-Luc-Picard-2021 CPython and most PSF projects use Discourse to discuss proposals. Discord is a quick way to talk to people for design suggestions before creating a Discourse topic, but in my opinion can be skipped if you have a concrete enough proposal to debate with.

  15. added a commit that references this issue on Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytopic-multiprocessingtype-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions