Skip to content

Commit

Permalink
fix: upload: 多开时极小概率因二次删除锁文件触发 FileNotFoundError
Browse files Browse the repository at this point in the history
  • Loading branch information
yzqzss committed Jul 25, 2023
1 parent 26ce3f5 commit 4c0516d
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions biliarchiver/utils/dirLock.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,12 @@ def __exit__(self, exc_type, exc_val, exc_tb):
if self.lock_file_fd is None:
raise IOError("Lock file not opened.")
self.fcntl.lockf(self.lock_file_fd, self.fcntl.LOCK_UN)
self.lock_file_fd.close()
os.remove(self.lock_file)
self.lock_file_fd.close() # lock_file_fd.close() 之后,其他进程有机会在本进程删掉锁文件之前拿到新锁
try:
os.remove(self.lock_file) # 删除文件不影响其他进程已持有的 inode 新锁
except FileNotFoundError:
# 如果抢到新锁的是本进程,删除文件的是其他进程,那么本进程再删除时自然会 FileNotFoundError,忽略就好
pass
# print("Released lock.")

# decorator
Expand Down

0 comments on commit 4c0516d

Please sign in to comment.