Lock files in binary mode, with one byte

This commit is contained in:
shortcutme 2019-03-15 23:53:48 +01:00
parent cd9a965057
commit a49f454826
No known key found for this signature in database
GPG key ID: 5B63BAE6CB9613AE

View file

@ -36,7 +36,7 @@ def atomicWrite(dest, content, mode="wb"):
return False return False
def openLocked(path, mode="w"): def openLocked(path, mode="wb"):
if os.name == "posix": if os.name == "posix":
import fcntl import fcntl
f = open(path, mode) f = open(path, mode)
@ -44,7 +44,7 @@ def openLocked(path, mode="w"):
elif os.name == "nt": elif os.name == "nt":
import msvcrt import msvcrt
f = open(path, mode) f = open(path, mode)
msvcrt.locking(f.fileno(), msvcrt.LK_NBLCK, -1) msvcrt.locking(f.fileno(), msvcrt.LK_NBLCK, 1)
else: else:
f = open(path, mode) f = open(path, mode)
return f return f