diff options
author | Dmitry Kopylov <kopylovd@gmail.com> | 2022-02-10 16:48:18 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:48:18 +0300 |
commit | b2f5101486cc0de2e979c8ba9ada2109785bf5fd (patch) | |
tree | affe28b840816b505db0467f2285b01c89c04247 /library/python/filelock/ut/lib/test_filelock.py | |
parent | e9b28b5aad71453a4637b70dde02e801e4147a2a (diff) | |
download | ydb-b2f5101486cc0de2e979c8ba9ada2109785bf5fd.tar.gz |
Restoring authorship annotation for Dmitry Kopylov <kopylovd@gmail.com>. Commit 1 of 2.
Diffstat (limited to 'library/python/filelock/ut/lib/test_filelock.py')
-rw-r--r-- | library/python/filelock/ut/lib/test_filelock.py | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/library/python/filelock/ut/lib/test_filelock.py b/library/python/filelock/ut/lib/test_filelock.py index 1b11d89123..4c985022d4 100644 --- a/library/python/filelock/ut/lib/test_filelock.py +++ b/library/python/filelock/ut/lib/test_filelock.py @@ -1,13 +1,13 @@ -import os -import time -import logging -import multiprocessing +import os +import time +import logging +import multiprocessing import tempfile import threading - + import library.python.filelock - - + + def _acquire_lock(lock_path, out_file_path): with library.python.filelock.FileLock(lock_path): with open(out_file_path, "a") as out: @@ -15,21 +15,21 @@ def _acquire_lock(lock_path, out_file_path): time.sleep(2) -def test_filelock(): +def test_filelock(): temp_dir = tempfile.mkdtemp() lock_path = os.path.join(temp_dir, "file.lock") out_file_path = os.path.join(temp_dir, "out.txt") - + process_count = 5 processes = [] for i in range(process_count): process = multiprocessing.Process(target=_acquire_lock, args=(lock_path, out_file_path)) process.start() processes.append(process) - + for process in processes: process.join() - + pids = [] times = [] with open(out_file_path) as out: @@ -39,7 +39,7 @@ def test_filelock(): pid, time_val = line.split(":") pids.append(pid) times.append(float(time_val)) - + assert len(set(pids)) == process_count time1 = times.pop() while times: |