From 7e4a5655173e43211d16cc9d223a77bfbc5bc77f Mon Sep 17 00:00:00 2001 From: Mathieu Pasquet Date: Wed, 29 Jan 2014 16:44:43 +0100 Subject: Fix a traceback when opening an empty log file --- src/logger.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/logger.py b/src/logger.py index fad57bec..7db34932 100644 --- a/src/logger.py +++ b/src/logger.py @@ -120,7 +120,13 @@ class Logger(object): # searching "\nM" nb times from the end of the file. We use mmap to # do that efficiently, instead of seek()s and read()s which are costly. with fd: - m = mmap.mmap(fd.fileno(), 0, prot=mmap.PROT_READ) + try: + m = mmap.mmap(fd.fileno(), 0, prot=mmap.PROT_READ) + except Exception: # file probably empty + log.error('Unable to mmap the log file for (%s)', + os.path.join(log_dir, jid), + exc_info=True) + return pos = m.rfind(b"\nM") # start of messages begin with MI or MR, # after a \n # number of message found so far -- cgit v1.2.3