From 7b1e03bf8e82bf7cebc8f76c507cdb78e8a3ed0a Mon Sep 17 00:00:00 2001 From: Shane Frischkorn Date: Wed, 12 Jan 2022 12:22:23 +1000 Subject: [PATCH] Fix bug where files downloaded directly do not exist when the watchdog event fires --- converter.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/converter.py b/converter.py index 887517f..fd0571d 100644 --- a/converter.py +++ b/converter.py @@ -70,6 +70,17 @@ class Handler(watchdog.events.PatternMatchingEventHandler): def on_created(self, event): print('File found: {}'.format(event.src_path)) + + fileExists = False + timeout = 0 + while not fileExists: + fileExists = os.path.isfile(event.src_path) + time.sleep(1) + timeout += 1 + + if timeout > 10: + print('Timeout waiting for file {} to exist. Aborting processing.'.format(event.src_path)) + return historicalSize = -1 while (historicalSize != os.path.getsize(event.src_path)):