Skip to content

Commit

Permalink
FileCache: update mtime of lockfile immediately after acquiring it (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
NeoLegends authored Nov 11, 2024
1 parent 492ddd8 commit d6d11d1
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions returnn/util/file_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ def _copy_file_if_needed(self, src_filename: str, dst_filename: str):
# Copy the file, while holding a lock. See comment on lock_timeout above.
with LockFile(
directory=dst_dir, name=os.path.basename(dst_filename) + ".lock", lock_timeout=self._lock_timeout
) as lock:
) as lock, self._touch_files_thread.files_added_context(lock.lockfile):
# Maybe it was copied in the meantime, while waiting for the lock.
if self._check_existing_copied_file_maybe_cleanup(src_filename, dst_filename):
print(f"FileCache: using existing file {dst_filename}")
Expand All @@ -349,7 +349,7 @@ def _copy_file_if_needed(self, src_filename: str, dst_filename: str):
f" to be older than {self._lock_timeout * 0.8:.1f}s but it is {dst_tmp_file_age} seconds old"
)

with self._touch_files_thread.files_added_context([dst_dir, lock.lockfile]):
with self._touch_files_thread.files_added_context(dst_dir):
# save mtime before the copy process to have it pessimistic
orig_mtime_ns = os.stat(src_filename).st_mtime_ns
FileInfo(mtime_ns=orig_mtime_ns).save(self._get_info_filename(dst_filename))
Expand Down

0 comments on commit d6d11d1

Please sign in to comment.