Skip to content

Commit 38e2f83

Browse files
committed
fix: don't delete file after filelock release to prevent race condition
tox-dev/filelock#31
1 parent b5e76b2 commit 38e2f83

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/pydiverse/pipedag/backend/lock/filelock.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,20 @@ def acquire(self, lockable: Lockable):
5050
lock_path = self.lock_path(lockable)
5151
self.locks[lockable] = fl.FileLock(lock_path)
5252

53-
f_lock = self.locks[lockable]
54-
if not f_lock.is_locked:
53+
lock = self.locks[lockable]
54+
if not lock.is_locked:
5555
self.logger.info(f"Locking '{lockable}'")
56-
f_lock.acquire()
56+
lock.acquire()
5757
self.set_lock_state(lockable, LockState.LOCKED)
5858

5959
def release(self, lockable: Lockable):
6060
if lockable not in self.locks:
6161
raise LockError(f"No lock '{lockable}' found.")
6262

63-
f_lock = self.locks[lockable]
64-
f_lock.release()
65-
66-
if not f_lock.is_locked:
63+
lock = self.locks[lockable]
64+
lock.release()
65+
if not lock.is_locked:
6766
self.logger.info(f"Unlocking '{lockable}'")
68-
os.remove(f_lock.lock_file)
6967
del self.locks[lockable]
7068
self.set_lock_state(lockable, LockState.UNLOCKED)
7169

0 commit comments

Comments
 (0)