Skip to content

Commit d313296

Browse files
committed
Suppress potential errors when releasing filelocks on unix
- closes #24609 - The `WindowsFileLock` class already has a suppression in place around `os.remove`. This commit adds a similar supression for `UnixFileLock` - These errors are typically raised when another instance of `emcc` released the lock file. This is a common pattern in the build systems of large projects. Ex: `ninja -j32`
1 parent 3622274 commit d313296

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

tools/filelock.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
# Modules
3939
# ------------------------------------------------
40+
from contextlib import suppress
4041
import logging
4142
import os
4243
import threading
@@ -410,8 +411,12 @@ def _acquire(self):
410411
def _release(self):
411412
fd = self._lock_file_fd
412413
self._lock_file_fd = None
413-
os.unlink(self._lock_file)
414-
fcntl.flock(fd, fcntl.LOCK_UN)
414+
# Probably another instance of the application
415+
# that acquired the file lock.
416+
with suppress(FileNotFoundError):
417+
os.unlink(self._lock_file)
418+
with suppress(OSError):
419+
fcntl.flock(fd, fcntl.LOCK_UN)
415420
os.close(fd)
416421
return None
417422

0 commit comments

Comments
 (0)