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

bpo-30457: Add new pending method for asyncio lock primitives by pfreixes · Pull Request #1786 · python/cpython · GitHub

Repository navigation

bpo-30457: Add new pending method for asyncio lock primitives - #1786

Closed
pfreixes wants to merge 1 commit into
python:masterfrom
pfreixes:enhancement-30457-add-new-pending-method-for-asyncio-lock-primitives
Closed

pfreixes wants to merge 1 commit into
python:masterfrom
pfreixes:enhancement-30457-add-new-pending-method-for-asyncio-lock-primitives

Conversation

Copy link
Copy Markdown

Currently, there is no way to access to the number of waiters pending to be woken up. This information can be useful for those environments which create and delete asyncio primitives instances depending if there are waiters still to be processed.

The following example shows an example of the DogPile solution that uses the Event lock mechanism. Each time that there is a miss in the cache, a new Event is created and it will be removed by the last waiter.

import asyncio

cache = {}
events = {}

async def get(process, key):
    try:
        return cache[key]
    except KeyError:
        try:
            await events[key].wait()
            if len(events[key]._waiters) == 0:
                events.pop(key)
            return cache[key]
        except KeyError:
            events[key] = asyncio.Event()
            # simulates some IO to get the Key
            await asyncio.sleep(0.1)
            cache[key] = "some random value"
            events[key].set()


async def main():
    tasks = [get(i, "foo") for i in range(1, 10)]
    await asyncio.gather(*tasks)

asyncio.get_event_loop().run_until_complete(main())

This PR make public and accessible the number of Python via the pending() method.

Copy link
Copy Markdown

@pfreixes, thanks for your PR! By analyzing the history of the files in this pull request, we identified @1st1, @asvetlov and @serhiy-storchaka to be potential reviewers.

1st1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Awaits green light on bpo.

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

1st1 commented Oct 19, 2017

Copy link
Copy Markdown
Member

Closing this one as its corresponding issue was rejected. @pfreixes Thanks a lot for proposing this though!

1st1 closed this Oct 19, 2017
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants


Back | FazBrowse Home | New Git URL