mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-24 08:03:53 +08:00
fix: 消除死锁隐患
This commit is contained in:
@@ -7,7 +7,6 @@ from config.manage_api_client import (
|
||||
get_server_config,
|
||||
get_agent_models,
|
||||
get_correct_words,
|
||||
lookup_address_book,
|
||||
DeviceNotFoundException,
|
||||
DeviceBindException,
|
||||
)
|
||||
@@ -24,7 +23,7 @@ def read_config(config_path):
|
||||
return config
|
||||
|
||||
|
||||
def load_config():
|
||||
async def load_config():
|
||||
"""加载配置文件"""
|
||||
from core.utils.cache.manager import cache_manager, CacheType
|
||||
|
||||
@@ -41,16 +40,7 @@ def load_config():
|
||||
custom_config = read_config(custom_config_path)
|
||||
|
||||
if custom_config.get("manager-api", {}).get("url"):
|
||||
import asyncio
|
||||
try:
|
||||
loop = asyncio.get_running_loop()
|
||||
# 如果已经在事件循环中,使用异步版本
|
||||
config = asyncio.run_coroutine_threadsafe(
|
||||
get_config_from_api_async(custom_config), loop
|
||||
).result()
|
||||
except RuntimeError:
|
||||
# 如果不在事件循环中(启动时),创建新的事件循环
|
||||
config = asyncio.run(get_config_from_api_async(custom_config))
|
||||
config = await get_config_from_api_async(custom_config)
|
||||
else:
|
||||
# 合并配置
|
||||
config = merge_configs(default_config, custom_config)
|
||||
@@ -139,7 +129,7 @@ def ensure_directories(config):
|
||||
selected_provider = selected_modules.get(module_type)
|
||||
if not selected_provider:
|
||||
continue
|
||||
if config.get(module) is None:
|
||||
if config.get(module_type) is None:
|
||||
continue
|
||||
if config.get(selected_provider) is None:
|
||||
continue
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import os
|
||||
import sys
|
||||
import asyncio
|
||||
from loguru import logger
|
||||
from config.config_loader import load_config
|
||||
from config.settings import check_config_file
|
||||
from datetime import datetime
|
||||
from core.utils.cache.manager import cache_manager, CacheType
|
||||
|
||||
SERVER_VERSION = "0.9.5"
|
||||
_logger_initialized = False
|
||||
@@ -45,10 +46,15 @@ def formatter(record):
|
||||
return record["message"]
|
||||
|
||||
|
||||
def setup_logging():
|
||||
check_config_file()
|
||||
def setup_logging(config=None):
|
||||
"""从配置文件中读取日志配置,并设置日志输出格式和级别"""
|
||||
config = load_config()
|
||||
if config is None:
|
||||
check_config_file()
|
||||
# 先查缓存,避免在 async 上下文中重复 await load_config
|
||||
config = cache_manager.get(CacheType.CONFIG, "main_config")
|
||||
if config is None:
|
||||
# 缓存也没有(理论上不该发生),才走 asyncio.run
|
||||
config = asyncio.run(load_config())
|
||||
log_config = config["log"]
|
||||
global _logger_initialized
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import os
|
||||
import asyncio
|
||||
from config.config_loader import read_config, get_project_dir, load_config
|
||||
|
||||
|
||||
@@ -20,7 +21,7 @@ def check_config_file():
|
||||
)
|
||||
|
||||
# 检查是否从API读取配置
|
||||
config = load_config()
|
||||
config = asyncio.run(load_config())
|
||||
if config.get("read_config_from_api", False):
|
||||
print("从API读取配置")
|
||||
old_config_origin = read_config(custom_config_file)
|
||||
|
||||
Reference in New Issue
Block a user