gh-346: Prompt to abort background downloads - #388
Merged
zooba merged 1 commit intoJul 31, 2026
Conversation
Punisheroot
marked this pull request as ready for review
July 31, 2026 10:17
Member
|
Thanks! I'm impressed at how you're matching the style of the surrounding code so well, most people (and AIs) don't manage that. |
Contributor
Author
|
Thank you! I think I’ve gotten into a bit of a flow state 😄 The context I gained from the previous PR definitely helped ❤️ |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
--yes.Context
BITS downloads intentionally continue in the background so that an interrupted installation can reuse the completed download on retry. However, an explicit Ctrl+C indicates that the user may want to stop the background transfer as well.
As discussed in the maintainer's design guidance, an interactive interruption should ask whether to abort the download, while
--yesshould default to aborting it.Currently,
KeyboardInterruptleaves_bits_urlretrievewithout giving the caller an opportunity to cancel the BITS job.Closes #346.
Changes
Cancellation prompt
download_packagenow supplies an optional cancellation callback tourlretrieve. The callback uses the existingcmd.ask_yn(...)confirmation mechanism, so it follows the normal command-line behavior:--yesaccepts the cancellation without prompting.BITS interruption handling
When
_bits_urlretrievereceivesKeyboardInterrupt, it now:.jobfile when confirmed;.jobfile when cancellation is declined;.jobfile and logs a warning if BITS cannot cancel the job;KeyboardInterruptin every case.Unexpected download errors retain their existing behavior. The WinHTTP, urllib, PowerShell, and local-file download paths are unchanged.
Tests
Added deterministic coverage for:
--yesas confirmation without interactive input.Validation
Performed on Windows with Python 3.14.6 and pytest 9.1.1:
4 passed);tests/test_urlutils.pyandtests/test_install_command.py: PASS (78 passed);git diff --check: PASS.The BITS interruption tests inject
KeyboardInterruptat the progress polling boundary. A manual interactive Ctrl+C test against a live background download was not performed.Compatibility and risk
The new
on_cancelcallback is optional, so existingurlretrievecallers retain their previous behavior. Only the BITS download path consults it afterKeyboardInterrupt; normal downloads and fallback selection are unaffected.The job metadata is removed only after
bits_cancelsucceeds. This avoids losing the ability to resume a background job when cancellation fails.