From a12f9fae7fc5a113f86970d6a65e9089ca07f393 Mon Sep 17 00:00:00 2001 From: Bakadax Date: Wed, 30 Apr 2025 18:35:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A6=82=E5=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/main.py b/src/main.py index c0e743d6..859a4df4 100644 --- a/src/main.py +++ b/src/main.py @@ -1,4 +1,5 @@ import asyncio +import atexit # 导入atexit import time from .plugins.utils.statistic import LLMStatistics from .plugins.moods.moods import MoodManager @@ -17,6 +18,7 @@ from .common.logger_manager import get_logger from .plugins.remote import heartbeat_thread # noqa: F401 from .individuality.individuality import Individuality from .common.server import global_server +from src.plugins.group_nickname.nickname_processor import start_nickname_processor, stop_nickname_processor logger = get_logger("main") @@ -177,11 +179,23 @@ class MainSystem: async def main(): """主函数""" system = MainSystem() - await asyncio.gather( - system.initialize(), - system.schedule_tasks(), - ) + # 注册退出处理函数 + atexit.register(stop_nickname_processor) # <--- 添加退出处理 + try: + # 启动绰号处理进程 + start_nickname_processor() # <--- 启动 + + await asyncio.gather( + system.initialize(), + system.schedule_tasks(), + ) + except KeyboardInterrupt: + print("程序被中断") + # finally 块不再需要手动调用 stop,atexit 会处理 + # finally: + # print("正在关闭...") + # stop_nickname_processor() # <--- 关闭 if __name__ == "__main__": - asyncio.run(main()) + asyncio.run(main()) \ No newline at end of file