Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't quite the right usage for uncancel. It should only be called if
self._reasons.pop(current_taskis set and then CancelledError should be re-raised if uncancel() != 0Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One option is to (on python3.11) use
And then
scope.reschedule(-1)to cancel the task, then we can rely on cpython code to catch the CancelledError and call uncancel() correctlyThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, but I won't rewrite the entire code for a py3.11 only option
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I already started on it here: #8109 😝
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's worth it as we can skip a load of bookkeeping for external/internal cancellation on 3.11, and "end-user code" isn't really supposed to call
.uncancel():There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also I was wrong on how to use uncancel() correctly here, You need to record the cancelling state: https://github.com/python/cpython/blob/e2420c5cae7a173c5242b3507979010a933e53a7/Lib/asyncio/timeouts.py#L87 then check https://github.com/python/cpython/blob/3.11/Lib/asyncio/timeouts.py#L108
if self._task.uncancel() <= self._cancelling and exc_type is exceptions.CancelledError: