From 9e32439f445af89bee0d662c83b7b1a7467b9e6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Fri, 27 Apr 2018 16:17:04 +0200 Subject: [PATCH] Watchdog: Ignore hidden & removed files Closes #2558 --- src/octoprint/server/util/watchdog.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/octoprint/server/util/watchdog.py b/src/octoprint/server/util/watchdog.py index 85f240cdb..1db1299e7 100644 --- a/src/octoprint/server/util/watchdog.py +++ b/src/octoprint/server/util/watchdog.py @@ -71,16 +71,28 @@ class GcodeWatchdogHandler(watchdog.events.PatternMatchingEventHandler): self._logger.exception("There was an error while processing the file {} in the watched folder".format(path)) def on_created(self, event): - thread = threading.Thread(target=self._repeatedly_check, args=(event.src_path,)) + path = event.src_path + if octoprint.util.is_hidden_path(path): + return + + thread = threading.Thread(target=self._repeatedly_check, args=(path,)) thread.daemon = True thread.start() def _repeatedly_check(self, path, interval=1, stable=5): - last_size = os.stat(path).st_size + try: + last_size = os.stat(path).st_size + except: + return + countdown = stable while True: - new_size = os.stat(path).st_size + try: + new_size = os.stat(path).st_size + except: + return + if new_size == last_size: self._logger.debug("File at {} is no longer growing, counting down: {}".format(path, countdown)) countdown -= 1