From 266da0a9d89a525d9694135967b59bab5668c10b Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Sun, 11 Aug 2024 02:30:49 -0400 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E9=87=8D=E5=90=AF?= =?UTF-8?q?=E6=97=B6=20aiocqhttp=20=E6=B2=A1=E6=9C=89=E6=AD=A3=E5=B8=B8?= =?UTF-8?q?=E9=80=80=E5=87=BA=E5=AF=BC=E8=87=B4=E7=AB=AF=E5=8F=A3=E5=8D=A0?= =?UTF-8?q?=E7=94=A8=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/bootstrap.py | 3 +++ dashboard/server.py | 4 ++-- model/command/internal_handler.py | 4 ++-- model/platform/qq_aiocqhttp.py | 2 +- type/types.py | 1 + util/updator/astrbot_updator.py | 6 ++++-- 6 files changed, 13 insertions(+), 7 deletions(-) diff --git a/astrbot/bootstrap.py b/astrbot/bootstrap.py index af64e0dd6..225ab08a9 100644 --- a/astrbot/bootstrap.py +++ b/astrbot/bootstrap.py @@ -100,6 +100,9 @@ class AstrBotBootstrap(): try: result = await task return result + except asyncio.CancelledError: + logger.info(f"{task.get_name()} 任务已取消。") + return except Exception as e: logger.error(traceback.format_exc()) logger.error(f"{task.get_name()} 任务发生错误,将在 5 秒后重试。") diff --git a/dashboard/server.py b/dashboard/server.py index e83a37161..60e880b51 100644 --- a/dashboard/server.py +++ b/dashboard/server.py @@ -311,7 +311,7 @@ class AstrBotDashBoard(): latest = False try: self.astrbot_updator.update(latest=latest, version=version) - threading.Thread(target=self.astrbot_updator._reboot, args=(3, )).start() + threading.Thread(target=self.astrbot_updator._reboot, args=(2, self.context)).start() return Response( status="success", message="更新成功,机器人将在 3 秒内重启。", @@ -374,7 +374,7 @@ class AstrBotDashBoard(): self.dashboard_data, self.context.config_helper.get_all()) # 重启 threading.Thread(target=self.astrbot_updator._reboot, - args=(2, ), daemon=True).start() + args=(2, self.context), daemon=True).start() except Exception as e: raise e diff --git a/model/command/internal_handler.py b/model/command/internal_handler.py index 377cd9df8..422c226f8 100644 --- a/model/command/internal_handler.py +++ b/model/command/internal_handler.py @@ -117,11 +117,11 @@ class InternalCommandHandler: success=False, message_chain="你没有权限使用该指令", ) - context.updator._reboot(5) + context.updator._reboot(3, context) return CommandResult( hit=True, success=True, - message_chain="AstrBot 将在 5s 后重启。", + message_chain="AstrBot 将在 3s 后重启。", ) def plugin(self, message: AstrMessageEvent, context: Context): diff --git a/model/platform/qq_aiocqhttp.py b/model/platform/qq_aiocqhttp.py index 89a699f69..31e025341 100644 --- a/model/platform/qq_aiocqhttp.py +++ b/model/platform/qq_aiocqhttp.py @@ -99,7 +99,7 @@ class AIOCQHTTP(Platform): return bot async def shutdown_trigger_placeholder(self): - while True: + while self.context.running: await asyncio.sleep(1) def pre_check(self, message: AstrBotMessage) -> bool: diff --git a/type/types.py b/type/types.py index 0e3fee1cd..06aad685f 100644 --- a/type/types.py +++ b/type/types.py @@ -44,6 +44,7 @@ class Context: self.ext_tasks: List[Task] = [] self.command_manager = None + self.running = True # useless self.reply_prefix = "" diff --git a/util/updator/astrbot_updator.py b/util/updator/astrbot_updator.py index bc80a7bd5..b6fbd9243 100644 --- a/util/updator/astrbot_updator.py +++ b/util/updator/astrbot_updator.py @@ -30,9 +30,11 @@ class AstrBotUpdator(RepoZipUpdator): except psutil.NoSuchProcess: pass - def _reboot(self, delay: int = None): - if delay: time.sleep(delay) + def _reboot(self, delay: int = None, context = None): + # if delay: time.sleep(delay) py = sys.executable + context.running = False + time.sleep(3) self.terminate_child_processes() py = py.replace(" ", "\\ ") try: