diff --git a/tools/filelock.py b/tools/filelock.py index 3c41dbcf45568..74b2e6baf6207 100644 --- a/tools/filelock.py +++ b/tools/filelock.py @@ -37,6 +37,7 @@ # Modules # ------------------------------------------------ +from contextlib import suppress import logging import os import threading @@ -410,8 +411,12 @@ def _acquire(self): def _release(self): fd = self._lock_file_fd self._lock_file_fd = None - os.unlink(self._lock_file) - fcntl.flock(fd, fcntl.LOCK_UN) + # Probably another instance of the application + # that released the file lock. + with suppress(FileNotFoundError): + os.unlink(self._lock_file) + with suppress(OSError): + fcntl.flock(fd, fcntl.LOCK_UN) os.close(fd) return None