From d0fe59631ce5169325b3a226a5a5ca64c1321154 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Wed, 22 Jan 2025 20:57:15 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E6=97=B6=E9=87=8D=E5=90=AF=E5=8F=AF=E8=83=BD?= =?UTF-8?q?=E4=BC=9A=E5=AF=BC=E8=87=B4Address=20already=20in=20use?= =?UTF-8?q?=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/dashboard/routes/update.py | 8 +++++--- astrbot/dashboard/server.py | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/astrbot/dashboard/routes/update.py b/astrbot/dashboard/routes/update.py index f2b5da9bd..d809a440b 100644 --- a/astrbot/dashboard/routes/update.py +++ b/astrbot/dashboard/routes/update.py @@ -1,14 +1,14 @@ -import threading import traceback from .route import Route, Response, RouteContext from quart import request +from astrbot.core.core_lifecycle import AstrBotCoreLifecycle from astrbot.core.updator import AstrBotUpdator from astrbot.core import logger, pip_installer from astrbot.core.utils.io import download_dashboard, get_dashboard_version from astrbot.core.config.default import VERSION class UpdateRoute(Route): - def __init__(self, context: RouteContext, astrbot_updator: AstrBotUpdator) -> None: + def __init__(self, context: RouteContext, astrbot_updator: AstrBotUpdator, core_lifecycle: AstrBotCoreLifecycle) -> None: super().__init__(context) self.routes = { '/update/check': ('GET', self.check_update), @@ -17,6 +17,7 @@ class UpdateRoute(Route): '/update/pip-install': ('POST', self.install_pip_package) } self.astrbot_updator = astrbot_updator + self.core_lifecycle = core_lifecycle self.register_routes() async def check_update(self): @@ -64,7 +65,8 @@ class UpdateRoute(Route): logger.error(f"下载管理面板文件失败: {e}。") if reboot: - threading.Thread(target=self.astrbot_updator._reboot, args=(2, )).start() + # threading.Thread(target=self.astrbot_updator._reboot, args=(2, )).start() + self.core_lifecycle.restart() return Response().ok(None, "更新成功,AstrBot 将在 2 秒内全量重启以应用新的代码。").__dict__ else: return Response().ok(None, "更新成功,AstrBot 将在下次启动时应用新的代码。").__dict__ diff --git a/astrbot/dashboard/server.py b/astrbot/dashboard/server.py index 71fca1586..c46bd3028 100644 --- a/astrbot/dashboard/server.py +++ b/astrbot/dashboard/server.py @@ -24,7 +24,7 @@ class AstrBotDashboard(): # token 用于验证请求 logging.getLogger(self.app.name).removeHandler(default_handler) self.context = RouteContext(self.config, self.app) - self.ur = UpdateRoute(self.context, core_lifecycle.astrbot_updator) + self.ur = UpdateRoute(self.context, core_lifecycle.astrbot_updator, core_lifecycle) self.sr = StatRoute(self.context, db, core_lifecycle) self.pr = PluginRoute(self.context, core_lifecycle, core_lifecycle.plugin_manager) self.cr = ConfigRoute(self.context, core_lifecycle)