File tree Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -52,14 +52,21 @@ def _acquire(self) -> None:
5252 msg = "FileSystem does not appear to support flock; use SoftFileLock instead"
5353 raise NotImplementedError (msg ) from exception
5454 else :
55- self ._context .lock_file_fd = fd
55+ st = os .fstat (fd )
56+ if st .st_nlink == 0 :
57+ # We raced with another process that deleted the lock file
58+ # before we called fcntl.flock. This means that lock is not
59+ # valid (since another process will just lock a different
60+ # file) and we need to try again.
61+ # See https://stackoverflow.com/a/51070775
62+ os .close (fd )
63+ else :
64+ self ._context .lock_file_fd = fd
5665
5766 def _release (self ) -> None :
58- # Do not remove the lockfile:
59- # https://github.com/tox-dev/py-filelock/issues/31
60- # https://stackoverflow.com/questions/17708885/flock-removing-locked-file-without-race-condition
6167 fd = cast ("int" , self ._context .lock_file_fd )
6268 self ._context .lock_file_fd = None
69+ Path .unlink (self .lock_file )
6370 fcntl .flock (fd , fcntl .LOCK_UN )
6471 os .close (fd )
6572
You can’t perform that action at this time.
0 commit comments