async-timeout icon indicating copy to clipboard operation
async-timeout copied to clipboard

Don't raise if the task already have been cancelled explicitly

Open asvetlov opened this issue 4 years ago • 4 comments
trafficstars

Fixes #229

asvetlov avatar Sep 04 '21 07:09 asvetlov

I'll try to manage the red CI on evening. Tests pass locally.

asvetlov avatar Sep 04 '21 09:09 asvetlov

CI is failing because this unfortunately still does not fix the second case. A cancellation can still be suppressed.

Dreamsorcerer avatar Sep 04 '21 12:09 Dreamsorcerer

I feel like there needs to be something new introduced to asyncio, so when looking at the CancelledError you can tell how many times cancel() was called before raising the exception and/or whether all cancellations were caused by us (i.e. was the sentinel sent for every cancellation).

Maybe the args on the exception could contain every msg from every cancel(). So, in these edge cases it would look like e.args == (None, _SENTINEL) from which we can see that there were 2 cancellations and only 1 was from our timeout. Then we can do a simple check like if all(msg is _SENTINEL for msg in e.args).

Dreamsorcerer avatar Sep 04 '21 12:09 Dreamsorcerer

Raised this as a proposal: https://bugs.python.org/issue45098

Dreamsorcerer avatar Sep 04 '21 13:09 Dreamsorcerer