From 437971ded84050907debef6dbce512e1de99242f Mon Sep 17 00:00:00 2001 From: RockChinQ <1010553892@qq.com> Date: Tue, 30 Jan 2024 14:58:34 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=BA=94=E7=94=A8=E5=B1=82=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/core/app.py | 11 ++++++++++- pkg/core/controller.py | 7 ++++--- pkg/platform/manager.py | 7 ++++++- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/pkg/core/app.py b/pkg/core/app.py index b2f23e8..cc36d4b 100644 --- a/pkg/core/app.py +++ b/pkg/core/app.py @@ -2,6 +2,7 @@ from __future__ import annotations import logging import asyncio +import traceback from ..platform import manager as im_mgr from ..provider.session import sessionmgr as llm_session_mgr @@ -65,4 +66,12 @@ class Application: asyncio.create_task(self.ctrl.run()) ] - await asyncio.wait(tasks, return_when=asyncio.FIRST_COMPLETED) + try: + + await asyncio.wait(tasks) + + except asyncio.CancelledError: + self.logger.info("程序退出.") + except Exception as e: + self.logger.error(f"应用运行致命异常: {e}") + self.logger.debug(f"Traceback: {traceback.format_exc()}") diff --git a/pkg/core/controller.py b/pkg/core/controller.py index ada46f7..eb6241a 100644 --- a/pkg/core/controller.py +++ b/pkg/core/controller.py @@ -61,8 +61,9 @@ class Controller: asyncio.create_task(_process_query(selected_query)) except Exception as e: - self.ap.logger.error(f"事件处理循环出错: {e}") - traceback.print_exc() + # traceback.print_exc() + self.ap.logger.error(f"控制器循环出错: {e}") + self.ap.logger.debug(f"Traceback: {traceback.format_exc()}") async def _check_output(self, result: pipeline_entities.StageProcessResult): """检查输出 @@ -144,7 +145,7 @@ class Controller: await self._execute_from_stage(0, query) except Exception as e: self.ap.logger.error(f"处理请求时出错 {query}: {e}") - traceback.print_exc() + self.ap.logger.debug(f"处理请求时出错 {query}: {e}", exc_info=True) finally: self.ap.logger.debug(f"Query {query} processed") diff --git a/pkg/platform/manager.py b/pkg/platform/manager.py index 921616c..7e8f581 100644 --- a/pkg/platform/manager.py +++ b/pkg/platform/manager.py @@ -4,6 +4,7 @@ import json import os import logging import asyncio +import traceback from mirai import At, GroupMessage, MessageEvent, StrangerMessage, \ FriendMessage, Image, MessageChain, Plain @@ -150,4 +151,8 @@ class QQBotManager: ) async def run(self): - await self.adapter.run_async() + try: + await self.adapter.run_async() + except Exception as e: + self.ap.logger.error('平台适配器运行出错: ' + str(e)) + self.ap.logger.debug(f"Traceback: {traceback.format_exc()}")