Skip to content

Commit a2484b3

Browse files
authored
Fix file locks in NFS-mounted directories (#517)
Fix #515.
1 parent 5ce4f1a commit a2484b3

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/petals/server/throughput.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def get_server_throughput(
5656

5757
# We use the system-wide lock since only one process at a time can measure the host throughput
5858
os.makedirs(lock_path.parent, exist_ok=True)
59-
with open(lock_path, "wb") as lock_fd:
59+
with open(lock_path, "wb+") as lock_fd:
6060
logger.info("Loading throughput info")
6161
fcntl.flock(lock_fd.fileno(), fcntl.LOCK_EX)
6262
# The OS will release the lock when lock_fd is closed or the process is killed

src/petals/utils/disk_cache.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def _blocks_lock(cache_dir: Optional[str], mode: int):
2222
lock_path = Path(cache_dir, BLOCKS_LOCK_FILE)
2323

2424
os.makedirs(lock_path.parent, exist_ok=True)
25-
with open(lock_path, "wb") as lock_fd:
25+
with open(lock_path, "wb+") as lock_fd:
2626
fcntl.flock(lock_fd.fileno(), mode)
2727
# The OS will release the lock when lock_fd is closed or the process is killed
2828
yield

0 commit comments

Comments
 (0)