diff --git a/cacholote/utils.py b/cacholote/utils.py index 615782a..2a6d420 100644 --- a/cacholote/utils.py +++ b/cacholote/utils.py @@ -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 @@ -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, diff --git a/tests/test_50_io_encoder.py b/tests/test_50_io_encoder.py index 3d14981..1ebf2cd 100644 --- a/tests/test_50_io_encoder.py +++ b/tests/test_50_io_encoder.py @@ -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)