✨ feat(run): add interrupt_post_commands for cleanup after Ctrl-C#3882
Merged
gaborbernat merged 2 commits intotox-dev:mainfrom Mar 17, 2026
Merged
✨ feat(run): add interrupt_post_commands for cleanup after Ctrl-C#3882gaborbernat merged 2 commits intotox-dev:mainfrom
gaborbernat merged 2 commits intotox-dev:mainfrom
Conversation
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
483ae33 to
0541f19
Compare
Users pressing Ctrl-C during test runs had no way to execute cleanup tasks in commands_post. The finally block ran, but commands_post commands were skipped because execute_async checks _interrupted and exits immediately. This prevented cleanup like stopping containers or removing temp files when tests were interrupted. Add interrupt_post_commands config option (default false). When enabled, first Ctrl-C interrupts commands but allows commands_post to run for cleanup. Second Ctrl-C interrupts commands_post. Track interrupt state with _fully_interrupted and _allow_interrupted_execution flags, add helper methods to toggle execution allowance, and modify run_commands to enable allowance for commands_post when configured. Fixes tox-dev#3858
gaborbernat
added a commit
to gaborbernat/tox
that referenced
this pull request
Mar 30, 2026
…x-dev#3882) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
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.
Users pressing Ctrl-C during test runs had no way to execute cleanup tasks in
commands_post. While the finally block ensurescommands_poststarts, the interrupt check inexecute_async()immediately exits withSystemExit(-2)before any commands execute. This prevents cleanup like stopping Docker containers or removing temp files when tests are interrupted.Add
interrupt_post_commandsconfig option (defaultfalse). When enabled, first Ctrl-C interruptscommandsandcommands_prebut allowscommands_postto proceed for cleanup. Second Ctrl-C duringcommands_postforces immediate termination. Implementation uses a context managerallow_post_commands_after_interrupt()that temporarily sets_allow_interrupted_executionflag to bypass the interrupt check, tracks interrupt levels with_fully_interruptedfor second Ctrl-C detection, and wrapscommands_postexecution in the context manager when the config is enabled.Tests verify cleanup runs after single Ctrl-C when enabled, doesn't run by default, and stops on second Ctrl-C. Cross-platform support uses
CTRL_C_EVENTon Windows andSIGINTon Unix.Fixes #3858