diff options
author | Mathieu Pasquet <mathieui@mathieui.net> | 2014-01-29 16:44:43 +0100 |
---|---|---|
committer | Mathieu Pasquet <mathieui@mathieui.net> | 2014-01-29 16:44:43 +0100 |
commit | 7e4a5655173e43211d16cc9d223a77bfbc5bc77f (patch) | |
tree | a3231ea4cd09d18a6cefcabcd17ccef10a7361b8 /src | |
parent | 8a44d31e85bc997255d6514bba1f4ee4a19f2da1 (diff) | |
download | poezio-7e4a5655173e43211d16cc9d223a77bfbc5bc77f.tar.gz poezio-7e4a5655173e43211d16cc9d223a77bfbc5bc77f.tar.bz2 poezio-7e4a5655173e43211d16cc9d223a77bfbc5bc77f.tar.xz poezio-7e4a5655173e43211d16cc9d223a77bfbc5bc77f.zip |
Fix a traceback when opening an empty log file
Diffstat (limited to 'src')
-rw-r--r-- | src/logger.py | 8 |
1 files changed, 7 insertions, 1 deletions
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 |