]> kaliko git repositories - mpd-sima.git/blobdiff - sima/utils/filelock.py
Some refactoring around Exceptions
[mpd-sima.git] / sima / utils / filelock.py
index 8f7065f7a4ff24af923ee779b6a46eead8775a9b..31df146831aeb5e8ea06497ea851fbfdf2dc3bf3 100644 (file)
@@ -1,7 +1,7 @@
 # -*- coding: utf-8 -*-
 
 # Copyright (c) 2009 Evan Fosmark
-# Copyright (c) 2014 Jack Kaliko <kaliko@azylum.org>
+# Copyright (c) 2014 kaliko <kaliko@azylum.org>
 #
 #   This program is free software: you can redistribute it and/or modify
 #   it under the terms of the GNU General Public License as published by
@@ -31,9 +31,10 @@ import errno
 import os
 import time
 
+
 class FileLockException(Exception):
     """FileLock Exception"""
-    pass
+
 
 class FileLock:
     """ A plain file lock whit context-manager"""
@@ -58,13 +59,13 @@ class FileLock:
         while True:
             try:
                 self.filedsc = os.open(self.lockfile,
-                                       os.O_CREAT|os.O_EXCL|os.O_RDWR)
+                                       os.O_CREAT | os.O_EXCL | os.O_RDWR)
                 break
             except OSError as err:
                 if err.errno != errno.EEXIST:
                     raise
                 if (time.time() - start_time) >= self.timeout:
-                    raise FileLockException('Timeout occured.')
+                    raise FileLockException('Timeout occured.') from err
                 time.sleep(self.delay)
         self.is_locked = True