Skip to content

Commit

Permalink
Make sure we don't read the file faster than it's being written.
Browse files Browse the repository at this point in the history
  • Loading branch information
nex3 committed Dec 18, 2008
1 parent aa65840 commit abd232f
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions mdb/watch.py
Expand Up @@ -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:
Expand Down

0 comments on commit abd232f

Please sign in to comment.