From 43ca9607f03b697df0dfc356ef1a3029551c9897 Mon Sep 17 00:00:00 2001 From: Collin Funk Date: Wed, 15 May 2024 20:25:38 -0700 Subject: [PATCH] gnulib-tool.py: Don't print tracebacks when Ctrl-C is pressed. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Suggested by Pádraig Brady in . * pygnulib/main.py (cli_exception): New function. (main_with_exception_handling): Use it. --- ChangeLog | 8 ++++++++ pygnulib/main.py | 11 +++++++++++ 2 files changed, 19 insertions(+) diff --git a/ChangeLog b/ChangeLog index 9a69d7e2aa..7690099cde 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2024-05-15 Collin Funk + + gnulib-tool.py: Don't print tracebacks when Ctrl-C is pressed. + Suggested by Pádraig Brady in + . + * pygnulib/main.py (cli_exception): New function. + (main_with_exception_handling): Use it. + 2024-05-15 Bruno Haible stdbit-h: Add tests. diff --git a/pygnulib/main.py b/pygnulib/main.py index dc0b2f4366..b693e71d7f 100644 --- a/pygnulib/main.py +++ b/pygnulib/main.py @@ -1365,7 +1365,18 @@ def main(temp_directory: str) -> None: pass +def cli_exception(exc_type, exc_value, exc_traceback) -> None: + '''Exception hook that does not print a traceback for KeyboardInterrupts + thrown when Ctrl-C is pressed.''' + if not issubclass(exc_type, KeyboardInterrupt): + sys.__excepthook__(exc_type, exc_value, exc_traceback) + + def main_with_exception_handling() -> None: + # Don't print tracebacks for KeyboardInterrupts when stdin is a tty. + if sys.stdin and sys.stdin.isatty(): + sys.excepthook = cli_exception + try: # Try to execute with tempfile.TemporaryDirectory(prefix='glpy') as temporary_directory: main(temporary_directory) -- 2.39.5