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: