fix: 修复重启报错问题(关联 #1460)

使用subprocess.Popen启动新进程,修复原方案识别路径空格的问题
This commit is contained in:
Anchor
2025-05-10 22:54:38 +08:00
committed by GitHub
parent b858401098
commit aff1698223
+16 -10
View File
@@ -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:
"""检查更新"""