-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cancel and fail downloads if exception happened #2710
Merged
artem-shelkovnikov
merged 4 commits into
main
from
artem/cancel-download-tasks-if-something-goes-wrong
Jul 17, 2024
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
86aea00
Cancel and fail downloads if exception happened
artem-shelkovnikov 14313c9
Make autoformat
artem-shelkovnikov 6b65bd1
Actually raise when cancelling downloads too
artem-shelkovnikov b0c3f4c
Merge branch 'main' into artem/cancel-download-tasks-if-something-goe…
artem-shelkovnikov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
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 couldn't find a clear answer on this; is the
finally
block still called if an error is raised in the caught exception block?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.
Yup, see this for example:
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.
In that case, the
finally
block is awaiting all of the downloads even if there's an error. But I guesslazy_downloads.cancel()
is wiping everything, so that's okay?(Asking because the PR title is
Cancel and fail downloads if exception happened
but it looks like it will still eventually await the downloads).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.
Yeah it's intended:
Cancellation does not mean that the task is immediately dead - we need to make sure that the task has an opportunity to gracefully cancel.
For example if the cancelled task catches
asyncio.CancelledError
and does something, then it will still need to be awaited.We use similar logic here:
connectors/connectors/services/base.py
Lines 177 to 182 in 8b8cb0d
task.cancelI()
injects the throw of asyncio.CancelledError where it can (pretty much anyawait
orasync with
statement). After that the code can catch it or not. Theexcept
part here is checking that task re-raisedasyncio.CancelledError
cause it could not handle it - there was noexcept asyncio.CancelledError
inside task or this error was re-raised.Hope the description makes sense, if not I can prepare an illustrative example of this :)
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.
That's really helpful, thanks!