Skip to content

Commit

Permalink
Own rather than extend SoftFileLock since it seems to cause issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanbb committed Jun 7, 2024
1 parent 66ad95d commit 36a73d7
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions mesmerize_core/batch_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,15 +259,18 @@ class OverwriteError(IndexError):
pass


class BatchLock(SoftFileLock):
"""Locks a batch file for safe writing, returning the dataframe in the 'as' clause"""
class BatchLock:
"""Locks a batch file for safe writing, returning the dataframe in the target"""
def __init__(self, batch_path: Union[Path, str], *args, **kwargs):
super().__init__(str(batch_path) + ".lock", *args, **kwargs)
self.lock = SoftFileLock(str(batch_path) + ".lock", *args, **kwargs)
self.batch_path = batch_path

def __enter__(self) -> pd.DataFrame:
super().__enter__() # may throw Timeout
self.lock.__enter__() # may throw Timeout
return load_batch(self.batch_path)

def __exit__(self, exc_type, exc_value, traceback):
self.lock.__exit__(exc_type, exc_value, traceback)


def open_batch_for_safe_writing(batch_path: Union[Path, str], lock_timeout: float = 30) -> BatchLock:
Expand Down

0 comments on commit 36a73d7

Please sign in to comment.