| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
|
@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. |
Sorry, something went wrong.
There was a problem hiding this comment.
Awaits green light on bpo.
Sorry, something went wrong.
|
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. |
Sorry, something went wrong.
|
Closing this one as its corresponding issue was rejected. @pfreixes Thanks a lot for proposing this though! |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
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.