X-Git-Url: https://git.kaliko.me/?a=blobdiff_plain;f=sima%2Futils%2Ffilelock.py;h=b5c51b6765f17d2f247693529157e07c09bc7aab;hb=beba5ba73dbb1b5c4d6161e472f89fe18f14aeeb;hp=128815a8fb179ff478fbce89472f114631416331;hpb=4ea8f2fe3f29fe09e7a3ab60ac781d54841db5bb;p=mpd-sima.git diff --git a/sima/utils/filelock.py b/sima/utils/filelock.py index 128815a..b5c51b6 100644 --- a/sima/utils/filelock.py +++ b/sima/utils/filelock.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # Copyright (c) 2009 Evan Fosmark -# Copyright (c) 2014 kaliko +# Copyright (c) 2014, 2021 kaliko # # 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 @@ -47,7 +47,7 @@ class FileLock: self.filedsc = None self.is_locked = False dirname = os.path.dirname(file_name) - self.lockfile = os.path.join(dirname, '{0}.lock'.format(file_name)) + self.lockfile = os.path.join(dirname, 'f{file_name}.lock') self.file_name = file_name self.timeout = timeout self.delay = delay @@ -59,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 @@ -84,7 +84,7 @@ class FileLock: self.acquire() return self - def __exit__(self, type, value, traceback): + def __exit__(self, ex_type, ex_value, ex_traceback): """end of the with statement """ if self.is_locked: