diff --git a/main.py b/main.py index e1bf87e..c8f3dab 100644 --- a/main.py +++ b/main.py @@ -57,6 +57,7 @@ def main(): while True: events = inotify.read(timeout=1000) if events: + scan_needed = False for event in events: logging.debug(f"Event: {event!r}") if event.mask & flags.IGNORED: @@ -76,12 +77,15 @@ def main(): add_watch_recursive(inotify, new_dir_path, watch_flags, wd_to_path) continue - if timer: - timer.cancel() - logging.info('Debounce cancelled timer.') - timer = threading.Timer(SCAN_DELAY_SECONDS, trigger_scan) - timer.start() - logging.info(f"Modification detected. Triggering scan in {SCAN_DELAY_SECONDS} seconds.") + scan_needed = True + + if scan_needed: + if timer: + timer.cancel() + logging.info('Debounce cancelled timer.') + timer = threading.Timer(SCAN_DELAY_SECONDS, trigger_scan) + timer.start() + logging.info(f"Modification detected. Triggering scan in {SCAN_DELAY_SECONDS} seconds.") except KeyboardInterrupt: logging.info("Shutting down...") finally: