Message370867
> Specifically a future can't be cancelled once it reaches the PENDING state, this is indicated when future.cancel() returns false; see https://github.com/python/cpython/blob/0e96c419d7287c3c7f155c9f2de3c61020386256/Lib/asyncio/futures.py#L152 for the source code
Actually, I was mistaken in my previous message; sorry about that. It can *only* be cancelled when the state is PENDING. So, I suspect there's a race condition where the state is `PENDING` when future.cancel() is called, but transitions to `FINISHED` before the future is actually cancelled. I'll insert some logging in `future.cancel()` to verify this locally.
The approach in PR-20686 has a fundamental problem though: simply because cancellation was requested does not mean the future was cancelled. So, we can't rely on checking ``self.done() and self._cancel_requested`` for future.cancelled() as this would mean that future.cancelled() would return true for a future that fully completed if `future.cancel()` was called after it finished (which is incorrect).
I'll have to do some further investigation to determine the cause and a potential fix of the race condition. Thanks again for reporting it, and my apologies for the earlier mixup. |
|
Date |
User |
Action |
Args |
2020-06-07 03:14:08 | aeros | set | recipients:
+ aeros, asvetlov, yselivanov, timmwagener |
2020-06-07 03:14:07 | aeros | set | messageid: <1591499647.93.0.374998392194.issue40894@roundup.psfhosted.org> |
2020-06-07 03:14:07 | aeros | link | issue40894 messages |
2020-06-07 03:14:07 | aeros | create | |
|