From 6d8a3b9897e714d02c7ac48ef3349d60c0621f19 Mon Sep 17 00:00:00 2001 From: Raven95676 Date: Tue, 13 May 2025 10:10:58 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=9B=9E=E9=80=80=E8=87=B3os.execl?= =?UTF-8?q?=E4=BB=A5=E5=85=BC=E5=AE=B9docker=EF=BC=8C=E6=94=B9=E7=94=A8?= =?UTF-8?q?=E5=8F=8C=E5=BC=95=E5=8F=B7=E5=A4=84=E7=90=86=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E7=A9=BA=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/core/updator.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/astrbot/core/updator.py b/astrbot/core/updator.py index 9a5dcc02b..09c4dba9c 100644 --- a/astrbot/core/updator.py +++ b/astrbot/core/updator.py @@ -2,7 +2,6 @@ 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 @@ -43,9 +42,9 @@ class AstrBotUpdator(RepoZipUpdator): pass def _reboot(self, delay: int = 3): - """ - 重启当前程序,使用 subprocess.Popen 启动新进程并退出旧进程 + """重启当前程序 在指定的延迟后,终止所有子进程并重新启动程序 + 这里只能使用 os.execl 来重启程序 """ time.sleep(delay) self.terminate_child_processes() @@ -53,18 +52,16 @@ class AstrBotUpdator(RepoZipUpdator): try: if "astrbot" in os.path.basename(sys.argv[0]): # 兼容cli - cmd = [py, "-m", "astrbot.cli.__main__"] + sys.argv[1:] + args = [ + f'"{arg}"' if " " in arg else arg for arg in sys.argv[1:] + ] + os.execl(py, f'"{py}"', "-m", "astrbot.cli.__main__", *args) else: - cmd = [py] + sys.argv - - subprocess.Popen(cmd, start_new_session=True) - + os.execl(py, f'"{py}"', *sys.argv) except Exception as e: - logger.error(f"重启失败({py} {cmd},错误:{e}),请尝试手动重启。") + logger.error(f"重启失败({py}, {e}),请尝试手动重启。") raise e - os._exit(0) - async def check_update(self, url: str, current_version: str) -> ReleaseInfo: """检查更新""" return await super().check_update(self.ASTRBOT_RELEASE_API, VERSION)