From 460e0f9ed9a854961d0031ee495d747c8d646288 Mon Sep 17 00:00:00 2001 From: Wing Lian Date: Thu, 24 Jul 2025 16:10:38 -0400 Subject: [PATCH] improve handling of file lock when content is empty (#2959) --- src/axolotl/utils/data/lock.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/axolotl/utils/data/lock.py b/src/axolotl/utils/data/lock.py index f5ec1679b..afd1547af 100644 --- a/src/axolotl/utils/data/lock.py +++ b/src/axolotl/utils/data/lock.py @@ -46,7 +46,8 @@ class FileLockLoader: def _increment_counter(self): """Safely increment the process counter.""" if self.counter_path.exists(): - count = int(self.counter_path.read_text().strip()) + counter_content = self.counter_path.read_text().strip() + count = int(counter_content) if counter_content else 0 else: count = 0 self.counter_path.write_text(str(count + 1)) @@ -54,10 +55,11 @@ class FileLockLoader: def cleanup(self): """Clean up ready flag when last process is done.""" with FileLock(str(self.lock_file_path)): - count = int(self.counter_path.read_text().strip()) + counter_content = self.counter_path.read_text().strip() + count = int(counter_content) if counter_content else 0 count -= 1 - if count == 0: + if count <= 0: # Last process cleans everything up self.ready_flag_path.unlink(missing_ok=True) self.counter_path.unlink(missing_ok=True)