[Python-ideas] Enabling Event.set to notify all waiters with an exception
pfreixes at gmail.com
Tue Jul 18 17:33:00 EDT 2017
I came across with that idea trying to resolve a typical dogpile
pattern , having many DNS calls to the same domain because of a
miss in a DNS cache.
The usage of the the set either to notify that the waiters could be
awake and get the result from the cache or use it to notify that
something was wrong helped me to reduce the complexity of the code.
Just as an example:
if key in throttle_dns_events:
yield from throttle_dns_events[key].wait()
throttle_dns_events[key] = Event(loop=loop)
addrs = yield from \
resolver.resolve(host, port, family=family)
except Exception as e:
# any DNS exception, independently of the implementation
# is set for the waiters to raise the same exception.
Any error caught by the locker will be broadcasted to the waiters. For
example, a invalid hostname.
I tried to open a PR to the CPython implementation, and they claim
that the current interface of all of the locks objects behind the
asyncio.locks  module try to keep the same interface as the
threading one . Therefore, to modify the asyncio implementation
would need first a change in the threading interface.
I was determined to justify that change, but after a bit research, I
didn't find any example in other languages such as Java , C#  or
C++  allowing you to send an exception as a signal value to wake
up the sleeping threads.
is that enough to give up? I'm still reticent, I believe that this
simple change in the interface can help reducing the complexity to
handle errors in some scenarios.
I would like to gather more ideas, thoughts, and comments from you
about how can I still justify this change ...
More information about the Python-ideas