-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Custom abort behaviour #2112
Comments
This really caught me for a surprise. I'm using Typer for a CLI app and "Aborted!" message showed up on keyboard interrupt. No easy way to change or silence it appears. |
@roblight Yeah, it's confusing. I originally thought the program had crashed with some memory issue (SIGABRT). I ended up doing exception handling manually in my case, in order to override this. |
It sounds like what you both are asking for is just to not print the "Aborted" message, not to be able to customize it. As to teardown, you should use the standard |
@davidism I'm not sure if existing signal handlers can be removed using atexit, but that seems a bit hacky in any case. |
Using the Perhaps you're looking for context managers? https://click.palletsprojects.com/en/8.0.x/advanced/#managing-resources |
Would I be able to remove the default exit handle in that case? The one that click provides. |
Currently, when Ctrl+C is pressed, a Click program "aborts" (printing "Aborted!") and immediately exits. I would like to be able to customise this behaviour, principally for the purpose of executing "teardown" code before the app exits, but it might also be nice to be able to customise the message to conform with a particular message style.
As far as I'm aware, there is no other way to solve this without turning off exception handling entirely, which is far from ideal.
The text was updated successfully, but these errors were encountered: