File tree 1 file changed +10
-5
lines changed
1 file changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -395,16 +395,21 @@ def _acquire(self):
395
395
except (IOError , OSError ):
396
396
os .close (fd )
397
397
else :
398
- self ._lock_file_fd = fd
398
+ st = os .fstat (fd );
399
+ if st .st_nlink == 0 :
400
+ # We raced with another process that deleted the lock file
401
+ # before we called fcntl.flock. This means that lock is not valie and we need to try
402
+ # again.
403
+ # See https://stackoverflow.com/a/51070775
404
+ os .close (fd )
405
+ else :
406
+ self ._lock_file_fd = fd
399
407
return None
400
408
401
409
def _release (self ):
402
- # Do not remove the lockfile:
403
- #
404
- # https://github.com/benediktschmitt/py-filelock/issues/31
405
- # https://stackoverflow.com/questions/17708885/flock-removing-locked-file-without-race-condition
406
410
fd = self ._lock_file_fd
407
411
self ._lock_file_fd = None
412
+ os .unlink (self ._lock_file )
408
413
fcntl .flock (fd , fcntl .LOCK_UN )
409
414
os .close (fd )
410
415
return None
You can’t perform that action at this time.
0 commit comments