From: Collin Funk Date: Thu, 16 May 2024 03:25:38 +0000 (-0700) Subject: gnulib-tool.py: Don't print tracebacks when Ctrl-C is pressed. X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=43ca9607f03b697df0dfc356ef1a3029551c9897;p=gnulib.git 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. --- 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)