homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author pfreixes
Recipients pfreixes, yselivanov
Date 2017年05月24日.14:48:25
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1495637305.13.0.0526704297983.issue30457@psf.upfronthosting.co.za>
In-reply-to
Content
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())
History
Date User Action Args
2017年05月24日 14:48:25pfreixessetrecipients: + pfreixes, yselivanov
2017年05月24日 14:48:25pfreixessetmessageid: <1495637305.13.0.0526704297983.issue30457@psf.upfronthosting.co.za>
2017年05月24日 14:48:25pfreixeslinkissue30457 messages
2017年05月24日 14:48:25pfreixescreate

AltStyle によって変換されたページ (->オリジナル) /