diff --git a/main/xiaozhi-server/core/utils/wakeup_word.py b/main/xiaozhi-server/core/utils/wakeup_word.py index 258f879b..29929081 100644 --- a/main/xiaozhi-server/core/utils/wakeup_word.py +++ b/main/xiaozhi-server/core/utils/wakeup_word.py @@ -2,9 +2,8 @@ import os import yaml import time import hashlib -import fcntl +import portalocker from typing import Dict -from contextlib import contextmanager class FileLock: @@ -17,15 +16,15 @@ class FileLock: self.start_time = time.time() while True: try: - fcntl.flock(self.file, fcntl.LOCK_EX | fcntl.LOCK_NB) + portalocker.lock(self.file, portalocker.LOCK_EX | portalocker.LOCK_NB) return self.file - except IOError: + except portalocker.LockException: if time.time() - self.start_time > self.timeout: raise TimeoutError("获取文件锁超时") time.sleep(0.1) def __exit__(self, exc_type, exc_val, exc_tb): - fcntl.flock(self.file, fcntl.LOCK_UN) + portalocker.unlock(self.file) class WakeupWordsConfig: diff --git a/main/xiaozhi-server/requirements.txt b/main/xiaozhi-server/requirements.txt index dc5a2294..3ffbcfa4 100755 --- a/main/xiaozhi-server/requirements.txt +++ b/main/xiaozhi-server/requirements.txt @@ -32,4 +32,5 @@ aioconsole==0.8.1 markitdown==0.1.1 mcp-proxy==0.6.0 PyJWT==2.8.0 -psutil==7.0.0 \ No newline at end of file +psutil==7.0.0 +portalocker==2.10.1 \ No newline at end of file