context_managers: Open file in write mode in lockfile_nonblocking.

Otherwise this fails if the file doesn't yet exist.
This commit is contained in:
Mateusz Mandera 2024-03-06 04:19:48 +01:00
parent b20beda905
commit dd6516d157
1 changed files with 1 additions and 1 deletions

View File

@ -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)