From aff1698223a95ba00e45f7d60550b1fa4fe3271b Mon Sep 17 00:00:00 2001 From: Anchor <123135745+anchorAnc@users.noreply.github.com> Date: Sat, 10 May 2025 22:54:38 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E9=87=8D=E5=90=AF?= =?UTF-8?q?=E6=8A=A5=E9=94=99=E9=97=AE=E9=A2=98=EF=BC=88=E5=85=B3=E8=81=94?= =?UTF-8?q?=20#1460=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 使用subprocess.Popen启动新进程,修复原方案识别路径空格的问题 --- astrbot/core/updator.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/astrbot/core/updator.py b/astrbot/core/updator.py index 60ed6860f..64fed52c7 100644 --- a/astrbot/core/updator.py +++ b/astrbot/core/updator.py @@ -42,24 +42,30 @@ class AstrBotUpdator(RepoZipUpdator): pass def _reboot(self, delay: int = 3): - """重启当前程序 + """ + 重启当前程序,使用 subprocess.Popen 启动新进程并退出旧进程 在指定的延迟后,终止所有子进程并重新启动程序 """ - py = sys.executable time.sleep(delay) self.terminate_child_processes() - py = py.replace(" ", "\\ ") + py = sys.executable + try: - if "astrbot" in os.path.basename(sys.argv[0]): # 兼容cli - args = [ - f'"{arg}"' if " " in arg else arg for arg in sys.argv[1:] - ] - os.execl(py, py, "-m", "astrbot.cli.__main__", *args) + if "astrbot" in os.path.basename(sys.argv[0]): # 兼容cli + cmd = [py, "-m", "astrbot.cli.__main__"] + sys.argv[1:] else: - os.execl(py, py, *sys.argv) + cmd = [py] + sys.argv + + subprocess.Popen( + cmd, + start_new_session=True + ) + except Exception as e: - logger.error(f"重启失败({py}, {e}),请尝试手动重启。") + logger.error(f"重启失败({py} {cmd},错误:{e}),请尝试手动重启。") raise e + + os._exit(0) async def check_update(self, url: str, current_version: str) -> ReleaseInfo: """检查更新""" From 25d87463270959beddefdc8ff9877126b21b9eda Mon Sep 17 00:00:00 2001 From: Anchor <123135745+anchorAnc@users.noreply.github.com> Date: Sat, 10 May 2025 23:00:55 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E8=A1=A5=E5=85=85=E4=B8=80=E4=B8=AAimport?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/core/updator.py | 1 + 1 file changed, 1 insertion(+) diff --git a/astrbot/core/updator.py b/astrbot/core/updator.py index 64fed52c7..9f108feb8 100644 --- a/astrbot/core/updator.py +++ b/astrbot/core/updator.py @@ -2,6 +2,7 @@ import os import psutil import sys import time +import subprocess from .zip_updator import ReleaseInfo, RepoZipUpdator from astrbot.core import logger from astrbot.core.config.default import VERSION From 7a7fd4167ae020cf2c541613ba0b53e765562b27 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Sat, 10 May 2025 12:21:21 -0400 Subject: [PATCH 3/3] style: format code --- astrbot/core/updator.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/astrbot/core/updator.py b/astrbot/core/updator.py index 9f108feb8..9a5dcc02b 100644 --- a/astrbot/core/updator.py +++ b/astrbot/core/updator.py @@ -50,22 +50,19 @@ class AstrBotUpdator(RepoZipUpdator): time.sleep(delay) self.terminate_child_processes() py = sys.executable - + try: - if "astrbot" in os.path.basename(sys.argv[0]): # 兼容cli + if "astrbot" in os.path.basename(sys.argv[0]): # 兼容cli cmd = [py, "-m", "astrbot.cli.__main__"] + sys.argv[1:] else: cmd = [py] + sys.argv - - subprocess.Popen( - cmd, - start_new_session=True - ) - + + subprocess.Popen(cmd, start_new_session=True) + except Exception as e: logger.error(f"重启失败({py} {cmd},错误:{e}),请尝试手动重启。") raise e - + os._exit(0) async def check_update(self, url: str, current_version: str) -> ReleaseInfo: @@ -80,7 +77,7 @@ class AstrBotUpdator(RepoZipUpdator): file_url = None if os.environ.get("ASTRBOT_CLI"): - raise Exception("不支持更新CLI启动的AstrBot") # 避免版本管理混乱 + raise Exception("不支持更新CLI启动的AstrBot") # 避免版本管理混乱 if latest: latest_version = update_data[0]["tag_name"]