From dd6516d157348bed2adb034b0103f04476972125 Mon Sep 17 00:00:00 2001 From: Mateusz Mandera Date: Wed, 6 Mar 2024 04:19:48 +0100 Subject: [PATCH] context_managers: Open file in write mode in lockfile_nonblocking. Otherwise this fails if the file doesn't yet exist. --- zerver/lib/context_managers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zerver/lib/context_managers.py b/zerver/lib/context_managers.py index 5010973e66..8728d87dd2 100644 --- a/zerver/lib/context_managers.py +++ b/zerver/lib/context_managers.py @@ -37,7 +37,7 @@ def lockfile_nonblocking(filename: str) -> Iterator[bool]: # nocoverage """Lock a file using flock(2) for the duration of a 'with' statement. Doesn't block, yields False immediately if the lock can't be acquired.""" - with open(filename) as f: + with open(filename, "w") as f: lock_acquired = False try: fcntl.flock(f, fcntl.LOCK_EX | fcntl.LOCK_NB)