increase compatibility with windows 11.
This commit is contained in:
24
mdrsclient/utils.py
Normal file
24
mdrsclient/utils.py
Normal 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)
|
Reference in New Issue
Block a user