Message388061
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. |
|
Date |
User |
Action |
Args |
2021-03-03 21:33:14 | nmatravolgyi | set | recipients:
+ nmatravolgyi, asvetlov, yselivanov |
2021-03-03 21:33:14 | nmatravolgyi | set | messageid: <1614807194.9.0.422304083833.issue43389@roundup.psfhosted.org> |
2021-03-03 21:33:14 | nmatravolgyi | link | issue43389 messages |
2021-03-03 21:33:14 | nmatravolgyi | create | |
|