Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

relax locker #118

Merged
merged 1 commit into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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