diff options
author | Nikita Slyusarev <nslus@yandex-team.com> | 2022-02-10 16:46:52 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:52 +0300 |
commit | cd77cecfc03a3eaf87816af28a33067c4f0cdb59 (patch) | |
tree | 1308e0bae862d52e0020d881fe758080437fe389 /library/python/filelock | |
parent | cdae02d225fb5b3afbb28990e79a7ac6c9125327 (diff) | |
download | ydb-cd77cecfc03a3eaf87816af28a33067c4f0cdb59.tar.gz |
Restoring authorship annotation for Nikita Slyusarev <nslus@yandex-team.com>. Commit 1 of 2.
Diffstat (limited to 'library/python/filelock')
-rw-r--r-- | library/python/filelock/__init__.py | 24 | ||||
-rw-r--r-- | library/python/filelock/ut/lib/test_filelock.py | 18 | ||||
-rw-r--r-- | library/python/filelock/ut/lib/ya.make | 2 | ||||
-rw-r--r-- | library/python/filelock/ya.make | 6 |
4 files changed, 25 insertions, 25 deletions
diff --git a/library/python/filelock/__init__.py b/library/python/filelock/__init__.py index f81ff67f37..cdf2ee4f68 100644 --- a/library/python/filelock/__init__.py +++ b/library/python/filelock/__init__.py @@ -1,12 +1,12 @@ -import errno -import logging -import os +import errno +import logging +import os import sys import library.python.windows logger = logging.getLogger(__name__) - + def set_close_on_exec(stream): if library.python.windows.on_win(): @@ -74,19 +74,19 @@ class _WinFileLock(AbstractFileLock): def __init__(self, path): super(_WinFileLock, self).__init__(path) self._lock = None - try: - with file(path, 'w') as lock_file: - lock_file.write(" " * self._LOCKED_BYTES_NUM) - except IOError as e: - if e.errno != errno.EACCES or not os.path.isfile(path): - raise + try: + with file(path, 'w') as lock_file: + lock_file.write(" " * self._LOCKED_BYTES_NUM) + except IOError as e: + if e.errno != errno.EACCES or not os.path.isfile(path): + raise def acquire(self, blocking=True): self._lock = open(self.path) set_close_on_exec(self._lock) import time - locked = False + locked = False while not locked: locked = library.python.windows.lock_file(self._lock, 0, self._LOCKED_BYTES_NUM, raises=False) if locked: @@ -97,7 +97,7 @@ class _WinFileLock(AbstractFileLock): return False def release(self): - if self._lock: + if self._lock: library.python.windows.unlock_file(self._lock, 0, self._LOCKED_BYTES_NUM, raises=False) self._lock.close() self._lock = None diff --git a/library/python/filelock/ut/lib/test_filelock.py b/library/python/filelock/ut/lib/test_filelock.py index 1b11d89123..5c2e0181ff 100644 --- a/library/python/filelock/ut/lib/test_filelock.py +++ b/library/python/filelock/ut/lib/test_filelock.py @@ -8,13 +8,13 @@ import threading import library.python.filelock -def _acquire_lock(lock_path, out_file_path): +def _acquire_lock(lock_path, out_file_path): with library.python.filelock.FileLock(lock_path): - with open(out_file_path, "a") as out: - out.write("{}:{}\n".format(os.getpid(), time.time())) - time.sleep(2) - - + with open(out_file_path, "a") as out: + out.write("{}:{}\n".format(os.getpid(), time.time())) + time.sleep(2) + + def test_filelock(): temp_dir = tempfile.mkdtemp() lock_path = os.path.join(temp_dir, "file.lock") @@ -46,12 +46,12 @@ def test_filelock(): time2 = times.pop() assert int(time1) - int(time2) >= 2 time1 = time2 - - + + def test_filelock_init_acquired(): temp_dir = tempfile.mkdtemp() lock_path = os.path.join(temp_dir, "file.lock") - + with library.python.filelock.FileLock(lock_path): sublock = library.python.filelock.FileLock(lock_path) del sublock diff --git a/library/python/filelock/ut/lib/ya.make b/library/python/filelock/ut/lib/ya.make index f3f9da5a67..291f8a32ba 100644 --- a/library/python/filelock/ut/lib/ya.make +++ b/library/python/filelock/ut/lib/ya.make @@ -2,7 +2,7 @@ OWNER(g:yatool) PY23_LIBRARY() -TEST_SRCS(test_filelock.py) +TEST_SRCS(test_filelock.py) PEERDIR( library/python/filelock diff --git a/library/python/filelock/ya.make b/library/python/filelock/ya.make index 958cc1866f..d67540b8f7 100644 --- a/library/python/filelock/ya.make +++ b/library/python/filelock/ya.make @@ -4,8 +4,8 @@ PY23_LIBRARY() PY_SRCS(__init__.py) -PEERDIR( - library/python/windows -) +PEERDIR( + library/python/windows +) END() |