update:修复windows平台无法使用fcntl模块的问题

This commit is contained in:
hrz
2025-06-09 00:20:49 +08:00
parent 423626a6bf
commit 7163abbbe3
2 changed files with 6 additions and 6 deletions
@@ -2,9 +2,8 @@ import os
import yaml import yaml
import time import time
import hashlib import hashlib
import fcntl import portalocker
from typing import Dict from typing import Dict
from contextlib import contextmanager
class FileLock: class FileLock:
@@ -17,15 +16,15 @@ class FileLock:
self.start_time = time.time() self.start_time = time.time()
while True: while True:
try: try:
fcntl.flock(self.file, fcntl.LOCK_EX | fcntl.LOCK_NB) portalocker.lock(self.file, portalocker.LOCK_EX | portalocker.LOCK_NB)
return self.file return self.file
except IOError: except portalocker.LockException:
if time.time() - self.start_time > self.timeout: if time.time() - self.start_time > self.timeout:
raise TimeoutError("获取文件锁超时") raise TimeoutError("获取文件锁超时")
time.sleep(0.1) time.sleep(0.1)
def __exit__(self, exc_type, exc_val, exc_tb): def __exit__(self, exc_type, exc_val, exc_tb):
fcntl.flock(self.file, fcntl.LOCK_UN) portalocker.unlock(self.file)
class WakeupWordsConfig: class WakeupWordsConfig:
+2 -1
View File
@@ -32,4 +32,5 @@ aioconsole==0.8.1
markitdown==0.1.1 markitdown==0.1.1
mcp-proxy==0.6.0 mcp-proxy==0.6.0
PyJWT==2.8.0 PyJWT==2.8.0
psutil==7.0.0 psutil==7.0.0
portalocker==2.10.1