Handle KeyboardInterrupt gracefully in ConcurrencyGroup#901
Open
Handle KeyboardInterrupt gracefully in ConcurrencyGroup#901
Conversation
When a user presses Ctrl+C, ConcurrencyGroup now sets the shutdown event and suppresses cleanup errors (strand timeouts, process failures) instead of producing scary ConcurrencyExceptionGroup tracebacks. The original KeyboardInterrupt propagates cleanly. Changes: - ConcurrencyGroup.__exit__: detect KeyboardInterrupt, call shutdown(), and suppress cleanup exceptions from _exit() - setup_command_context: detect active KeyboardInterrupt via sys.exc_info() and pass it to __exit__ (Click's call_on_close passes None by default) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Comment on lines
141
to
+145
| except BaseException as exit_exception: | ||
| if isinstance(exc_value, KeyboardInterrupt): | ||
| # When the user presses Ctrl+C, suppress cleanup errors (strand timeouts, process | ||
| # failures, etc.) and let the original KeyboardInterrupt propagate cleanly. | ||
| return |
Contributor
There was a problem hiding this comment.
isn't this suspicious? like, couldn't this have been caused by the user hitting ctrl c a bunch of times, eg, while inside of the exit() function above?
seems like we kinda need to do this a little bit differently / more robustly in practice...
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.
When a user presses Ctrl+C, ConcurrencyGroup now sets the shutdown event and suppresses cleanup errors (strand timeouts, process failures) instead of producing scary ConcurrencyExceptionGroup tracebacks. The original KeyboardInterrupt propagates cleanly.
Changes: