[Python-ideas] Enabling Event.set to notify all waiters with an exception
njs at pobox.com
Wed Jul 19 14:39:47 EDT 2017
On Jul 18, 2017 11:37 PM, "Pau Freixes" <pfreixes at gmail.com> wrote:
> 'Event' is designed as a lowish-level primitive: the idea is that it
> purely provides the operation of "waiting for something", and then you
> can compose it with other data structures to build whatever
> higher-level semantics you need.
> But I don't think adding exception-throwing functionality to Event()
> is the right solution :-)
Then I will be forced to make the code stateful, getting as an output
as a complex solution if you compare it with the code that you might
get using the Event()
Not really – the point of the first part of my message is that if you
really want a Future/Event hybrid that can raise an error from 'wait', then
python gives you the tools to implement this yourself, and then you can use
it however you like.
self._event = asyncio.Event()
self._error = None
def set(self, error=None):
self._error = error
async def wait(self):
if self._error is not None:
...and you're good to go.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas