From abd232fe883978f9e8154bd81cb44c224497a243 Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Thu, 18 Dec 2008 12:54:33 -0800 Subject: [PATCH] Make sure we don't read the file faster than it's being written. --- mdb/watch.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/mdb/watch.py b/mdb/watch.py index 5db6539..01b9e32 100644 --- a/mdb/watch.py +++ b/mdb/watch.py @@ -13,8 +13,17 @@ def __init__(self, server, name): def process_IN_CREATE(self, event): path = os.path.join(event.path, event.name) print "Adding %s..." % path - time.sleep(0.1) # Make sure the file is actually written - self.db.add(path) + + for attempt in range(10): + try: + self.db.add(path) + break + except EOFError: + if attempt < 9: + print "File not yet written, waiting a second..." + time.sleep(1) + else: + print "Giving up." mask = pyi.EventsCodes.IN_CREATE class Watcher: