FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Simplify consumers by making `queue.Queue` an iterable · Issue #120499 · python/cpython · GitHub

Repository navigation

Simplify consumers by making queue.Queue an iterable #120499

Closed as not planned
Closed as not planned

Description

Feature or enhancement

Proposal:

class Iterator:
    def __init__(self, queue):
        self.queue = queue

    def __iter__(self):
        return self

    async def __next__(self):
        try:
            return self.queue.get_nowait()
        except (Empty, ShutDown):
            raise StopIteration

class Queue:
    ...
    def __iter__(self):
        return Iterator(self)

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

Linked PRs

Activity

  1. changed the title [-]Add `queue.Queue.__iter__()`[/-] [+]Add `*.Queue.__iter__()`[/+] on Jun 14, 2024
  2. sobolevn commented on Jun 14, 2024

    Member

    This is a minor feature, which does not need previous discussion elsewhere

    Sorry, I might be missing something obvious, but can you please explain a motivation behind this change?

  3. zware commented on Jun 14, 2024

    Member

    @nineteendo, please stop editing your posts after submission. Edit before you submit, and don't submit until you aren't going to change it again. There is not a window in which substantial edits are okay; email notifications will only ever contain the original version, which at this point is much different than what is now here.

  4. nineteendo commented on Jun 14, 2024

    ContributorAuthor

    Sorry, I might be missing something obvious, but can you please explain a motivation behind this change?

    Guido suggested this here: python/peps#3782 (comment)

    Adding __aiter__ seems fairly uncontroversial now we have shutdown. It can just be discussed on Discourse. I'd recommend adding __iter__ to non-asyncio queues.Queue as well, just like we added shutdown to both.

    I've made a separate issue, because the title didn't match.


    please stop editing your posts after submission

    Reverted. I realised we didn't need a separate class, so that's why I use generator in the PR.

    Edit before you submit, and don't submit until you aren't going to change it again.

    Would you prefer me to create a new issue then?

  5. sobolevn commented on Jun 14, 2024

    Member

    @nineteendo thank you! Please, next time include this context in the issue :)

  6. zware commented on Jun 14, 2024

    Member

    Would you prefer me to create a new issue then?

    No, I would prefer that you stop editing your posts :). Not even to revert previous edits, just no more edits.

    My suggestion to edit before submission is intended for any post you make, not just new issues. Make sure you're saying what you want to say on the first try; there's no benefit to saying the wrong thing quickly when you have unlimited time to get it right. If your understanding of something changes, say so in a new message.

  7. nineteendo commented on Jun 15, 2024

    ContributorAuthor

    My suggestion to edit before submission is intended for any post you make, not just new issues.

    In the future I'll try to create an issue and PR on my own fork first. I don't make significant changes to regular comments (just fixing a typo or suggestion).

  8. nineteendo commented on Jun 15, 2024

    ContributorAuthor

    @Zac-HD, multiprocessing.Queue.close() doesn't prevent other processes from putting items on the queue.
    So, I'm not sure how we can make this work without a sentinel for every reading process.

  9. changed the title [-]Add `*.Queue.__iter__()`[/-] [+]Simplify consumers by making `queue.Queue` an iterable[/+] on Jun 21, 2024
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

    type-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL