bessagroup / f3dasm

Framework for Data-Driven Design & Analysis of Structures & Materials (F3DASM)
https://f3dasm.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
111 stars 29 forks source link

pd.EmptyData error in concurrent access `from_file` and `store` method #273

Open mpvanderschelling opened 2 months ago

mpvanderschelling commented 2 months ago

The Problem

While one process invokes the store() method and another process tries to read the ExperimentData object (from_file()), there is the possibility that when the _Data object invokes the to_csv method, the object is read from disk. Because the to_csv method first empties the files and then reads to it, the file can be read empty. This creates an pd.EmptyDataError. Especially when a large number of experiments need to be written.

Possible solution

Work with temporary file creation: store()

  1. to_csv to .tmp file
  2. Rename the file to .csv
  3. Remove the `.tmp file

from_file()

  1. Check for .tmp files in path. If exists, retry later
  2. If no `.tmp files, open like normally