Skip to content

Commit

Permalink
relax locker (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
malmans2 authored May 22, 2024
1 parent f786a8b commit 7fc27db
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
12 changes: 10 additions & 2 deletions cacholote/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,21 @@ def lockfile(self) -> str:
def acquire(self) -> None:
self.fs.touch(self.lockfile)

@property
def exists(self) -> bool:
return bool(self.fs.exists(self.urlpath))

@property
def lock_exists(self) -> bool:
return bool(self.fs.exists(self.lockfile))

def release(self) -> None:
if self.fs.exists(self.lockfile):
self.fs.rm(self.lockfile)

@property
def is_locked(self) -> bool:
return bool(self.fs.exists(self.lockfile))
return self.lock_exists and self.exists

def wait_until_released(self) -> None:
warned = False
Expand All @@ -107,7 +115,7 @@ def wait_until_released(self) -> None:
def __enter__(self) -> bool:
self.wait_until_released()
self.acquire()
return bool(self.fs.exists(self.urlpath))
return self.exists

def __exit__(
self,
Expand Down
1 change: 1 addition & 0 deletions tests/test_50_io_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ def test_io_locker(
# Acquire lock
fs, dirname = utils.get_cache_files_fs_dirname()
file_path = f"{dirname}/{fsspec.filesystem('file').checksum(tmpfile):x}.txt"
fs.touch(file_path)
fs.touch(f"{file_path}.lock")

process = subprocess.Popen(f"sleep 0.1; rm {file_path}.lock", shell=True)
Expand Down

0 comments on commit 7fc27db

Please sign in to comment.