increase compatibility with windows 11.

This commit is contained in:
2023-05-11 18:55:48 +09:00
parent b4780dd069
commit 5c41ed041d
3 changed files with 29 additions and 3 deletions

24
mdrsclient/utils.py Normal file
View File

@ -0,0 +1,24 @@
import os
from typing import IO, Any
if os.name == "nt":
import msvcrt
elif os.name == "posix":
import fcntl
class FileLock:
@staticmethod
def lock(file: IO[Any]) -> None:
if os.name == "nt":
msvcrt.locking(file.fileno(), msvcrt.LK_LOCK, 1)
elif os.name == "posix":
fcntl.flock(file.fileno(), fcntl.LOCK_EX)
@staticmethod
def unlock(file: IO[Any]) -> None:
if os.name == "nt":
msvcrt.locking(file.fileno(), msvcrt.LK_UNLCK, 1)
else:
fcntl.flock(file.fileno(), fcntl.LOCK_UN)