yes thats the behviour that I was looking for. The code its enought simple.
Using the shield as has been proposed to protect the cancellation, plus this pattern it will work. Thanks for the feedback and proposal, I will abandon the idea of modify the set method. Cheers, El 19/07/2017 20:39, "Nathaniel Smith" <n...@pobox.com> escribió: On Jul 18, 2017 11:37 PM, "Pau Freixes" <pfrei...@gmail.com> wrote: Yeps, > '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. Something like class ErrorfulOneShotEvent: def __init__(self): self._event = asyncio.Event() self._error = None def set(self, error=None): self._error = error self._event.set() async def wait(self): await self._event.wait() if self._error is not None: raise self._error ...and you're good to go.
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/