From a5bc1943ca26e0271e5e93497a21caca17cc1fe7 Mon Sep 17 00:00:00 2001 From: "J. Cernek" Date: Sat, 18 Feb 2023 19:05:12 +0100 Subject: [PATCH 1/2] [watchmedo] Exit gracefully on KeyboardInterrupt Exception (Ctrl+C keystroke) Uses system exit code 130. --- src/watchdog/watchmedo.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/watchdog/watchmedo.py b/src/watchdog/watchmedo.py index ff14df462..375365c2e 100755 --- a/src/watchdog/watchmedo.py +++ b/src/watchdog/watchmedo.py @@ -679,7 +679,11 @@ def main(): return 1 logging.getLogger('watchdog').setLevel(log_level) - args.func(args) + try: + args.func(args) + except KeyboardInterrupt: + return 130 + return 0 From 81469e9a827f3eda3f5031e96e57f3c69bdc004f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Schoentgen?= Date: Mon, 20 Feb 2023 20:34:04 +0100 Subject: [PATCH 2/2] Update changelog.rst --- changelog.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.rst b/changelog.rst index b4410ca48..f182e853d 100644 --- a/changelog.rst +++ b/changelog.rst @@ -10,6 +10,7 @@ Changelog - [inotify] Add support for ``IN_OPEN`` events: a ``FileOpenedEvent`` event will be fired. (`#941 `__) - [watchmedo] Add optional event debouncing for ``auto-restart``, only restarting once if many events happen in quick succession (`#940 `__) +- [watchmedo] Exit gracefully on ``KeyboardInterrupt`` exception (Ctrl+C) (`#945 `__) - Thanks to our beloved contributors: @BoboTiG, @dstaple, @taleinat 2.2.1