nmatravolgyi <nandor.ma...@gmail.com> added the comment:

One more thing. I've figured out that I can fix the cancellation around the 
asyncio.wait_for() with asyncio.shield() like:

try:
    await asyncio.shield(wf := 
asyncio.ensure_future(asyncio.wait_for(self.event.wait(), timeout=60.0)))
except asyncio.CancelledError:
    wf.cancel()
    result = await asyncio.gather(wf, return_exceptions=True)
    # here I know there is a cancellation AND I might have a result as well!
    raise

However I don't like the idea of writing all that boilerplate for every 
wait_for usage. I still might be overlooking something, but at least I have 
adequate workarounds.

I'm curious what the consensus will be on this issue. I'm certain it should be 
documented though. Right now there is no mention of ignoring/eating a 
cancellation.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue43389>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to