File tree 1 file changed +11
-4
lines changed 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:
52
52
msg = "FileSystem does not appear to support flock; use SoftFileLock instead"
53
53
raise NotImplementedError (msg ) from exception
54
54
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
56
65
57
66
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
61
67
fd = cast ("int" , self ._context .lock_file_fd )
62
68
self ._context .lock_file_fd = None
69
+ os .unlink (self .lock_file )
63
70
fcntl .flock (fd , fcntl .LOCK_UN )
64
71
os .close (fd )
65
72
You can’t perform that action at this time.
0 commit comments