Skip to content

asyncio.queues.Queue._wakeup_next can be changed to a static method #146363

@jonathandung

Description

@jonathandung

Feature or enhancement

Proposal:

Under the declaration of the asyncio.Queue class, in Lib/asyncio/queues.py:

    def _wakeup_next(self, waiters):
        # Wake up the next waiter (if any) that isn't cancelled.
        while waiters:
            waiter = waiters.popleft()
            if not waiter.done():
                waiter.set_result(None)
                break

It is clear that the self parameter is not used, since this is just a helper method, to reduce code duplication by separating out the common functionality of unblocking callers in Queue.get and Queue.put, with the waiters deque passed directly. Thus, _wakeup_next should be made static:

    @staticmethod
    def _wakeup_next(self, waiters):
        # Wake up the next waiter (if any) that isn't cancelled.
        while waiters:
            waiter = waiters.popleft()
            if not waiter.done():
                waiter.set_result(None)
                break

Since _wakeup_next is a private method, this change will be minor.

I will open a PR if required.

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:

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions