mirror of https://github.com/zulip/zulip.git
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:
parent
b20beda905
commit
dd6516d157
|
@ -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.
|
"""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."""
|
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
|
lock_acquired = False
|
||||||
try:
|
try:
|
||||||
fcntl.flock(f, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
fcntl.flock(f, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||||
|
|
Loading…
Reference in New Issue