mirror of
https://github.com/AstrBotDevs/AstrBot.git
synced 2026-10-29 17:24:47 +08:00
fix: update reboot logic to handle executable paths correctly
This commit is contained in:
+13
-7
@@ -44,20 +44,26 @@ class AstrBotUpdator(RepoZipUpdator):
|
|||||||
def _reboot(self, delay: int = 3):
|
def _reboot(self, delay: int = 3):
|
||||||
"""重启当前程序
|
"""重启当前程序
|
||||||
在指定的延迟后,终止所有子进程并重新启动程序
|
在指定的延迟后,终止所有子进程并重新启动程序
|
||||||
这里只能使用 os.execl 来重启程序
|
这里只能使用 os.exec* 来重启程序
|
||||||
"""
|
"""
|
||||||
time.sleep(delay)
|
time.sleep(delay)
|
||||||
self.terminate_child_processes()
|
self.terminate_child_processes()
|
||||||
py = sys.executable
|
if os.name == "nt":
|
||||||
|
py = f'"{sys.executable}"'
|
||||||
|
else:
|
||||||
|
py = sys.executable
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if "astrbot" in os.path.basename(sys.argv[0]): # 兼容cli
|
if "astrbot" in os.path.basename(sys.argv[0]): # 兼容cli
|
||||||
args = [
|
if os.name == "nt":
|
||||||
f'"{arg}"' if " " in arg else arg for arg in 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:
|
||||||
|
args = sys.argv[1:]
|
||||||
|
os.execl(sys.executable, py, "-m", "astrbot.cli.__main__", *args)
|
||||||
else:
|
else:
|
||||||
os.execl(py, f'"{py}"', *sys.argv)
|
os.execl(sys.executable, py, *sys.argv)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"重启失败({py}, {e}),请尝试手动重启。")
|
logger.error(f"重启失败({py}, {e}),请尝试手动重启。")
|
||||||
raise e
|
raise e
|
||||||
|
|||||||
Reference in New Issue
Block a user