Skip to content

Commit

Permalink
WIP racing conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
mpvanderschelling committed Feb 7, 2025
1 parent 838eea3 commit 49b07c6
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/f3dasm/_src/experimentdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,24 +305,22 @@ def wrapper_func(project_dir: Path, *args, **kwargs) -> None:
# Load a fresh instance of ExperimentData from file
loaded_self = ExperimentData.from_file(
self.project_dir)
# Call the operation with the loaded instance
# Replace the self in args with the loaded instance
# Modify the first argument
args = (loaded_self,) + args[1:]
value = operation(*args, **kwargs)
loaded_self.store()
break
# Racing conditions can occur when the file is empty
# and the file is being read at the same time
# Catch racing conditions
except (EmptyFileError, DecodeError):
tries += 1
logger.debug((
f"Error reading a file, retrying"
f" {tries+1}/{MAX_TRIES}"))
sleep(random.uniform(0.5, 2.5))

raise ReachMaximumTriesError(file_path=self.project_dir,
max_tires=tries)
if tries >= MAX_TRIES:
raise ReachMaximumTriesError(file_path=self.project_dir,
max_tires=tries)

args = (loaded_self,) + args[1:]
value = operation(*args, **kwargs)
loaded_self.store()

return value

Expand Down

0 comments on commit 49b07c6

Please sign in to comment.