mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-27 01:23:55 +08:00
update:修复windows平台无法使用fcntl模块的问题
This commit is contained in:
@@ -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:
|
||||||
|
|||||||
@@ -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
|
||||||
Reference in New Issue
Block a user