fix: 修复重启时 aiocqhttp 没有正常退出导致端口占用的问题
This commit is contained in:
@@ -100,6 +100,9 @@ class AstrBotBootstrap():
|
||||
try:
|
||||
result = await task
|
||||
return result
|
||||
except asyncio.CancelledError:
|
||||
logger.info(f"{task.get_name()} 任务已取消。")
|
||||
return
|
||||
except Exception as e:
|
||||
logger.error(traceback.format_exc())
|
||||
logger.error(f"{task.get_name()} 任务发生错误,将在 5 秒后重试。")
|
||||
|
||||
+2
-2
@@ -311,7 +311,7 @@ class AstrBotDashBoard():
|
||||
latest = False
|
||||
try:
|
||||
self.astrbot_updator.update(latest=latest, version=version)
|
||||
threading.Thread(target=self.astrbot_updator._reboot, args=(3, )).start()
|
||||
threading.Thread(target=self.astrbot_updator._reboot, args=(2, self.context)).start()
|
||||
return Response(
|
||||
status="success",
|
||||
message="更新成功,机器人将在 3 秒内重启。",
|
||||
@@ -374,7 +374,7 @@ class AstrBotDashBoard():
|
||||
self.dashboard_data, self.context.config_helper.get_all())
|
||||
# 重启
|
||||
threading.Thread(target=self.astrbot_updator._reboot,
|
||||
args=(2, ), daemon=True).start()
|
||||
args=(2, self.context), daemon=True).start()
|
||||
except Exception as e:
|
||||
raise e
|
||||
|
||||
|
||||
@@ -117,11 +117,11 @@ class InternalCommandHandler:
|
||||
success=False,
|
||||
message_chain="你没有权限使用该指令",
|
||||
)
|
||||
context.updator._reboot(5)
|
||||
context.updator._reboot(3, context)
|
||||
return CommandResult(
|
||||
hit=True,
|
||||
success=True,
|
||||
message_chain="AstrBot 将在 5s 后重启。",
|
||||
message_chain="AstrBot 将在 3s 后重启。",
|
||||
)
|
||||
|
||||
def plugin(self, message: AstrMessageEvent, context: Context):
|
||||
|
||||
@@ -99,7 +99,7 @@ class AIOCQHTTP(Platform):
|
||||
return bot
|
||||
|
||||
async def shutdown_trigger_placeholder(self):
|
||||
while True:
|
||||
while self.context.running:
|
||||
await asyncio.sleep(1)
|
||||
|
||||
def pre_check(self, message: AstrBotMessage) -> bool:
|
||||
|
||||
@@ -44,6 +44,7 @@ class Context:
|
||||
self.ext_tasks: List[Task] = []
|
||||
|
||||
self.command_manager = None
|
||||
self.running = True
|
||||
|
||||
# useless
|
||||
self.reply_prefix = ""
|
||||
|
||||
@@ -30,9 +30,11 @@ class AstrBotUpdator(RepoZipUpdator):
|
||||
except psutil.NoSuchProcess:
|
||||
pass
|
||||
|
||||
def _reboot(self, delay: int = None):
|
||||
if delay: time.sleep(delay)
|
||||
def _reboot(self, delay: int = None, context = None):
|
||||
# if delay: time.sleep(delay)
|
||||
py = sys.executable
|
||||
context.running = False
|
||||
time.sleep(3)
|
||||
self.terminate_child_processes()
|
||||
py = py.replace(" ", "\\ ")
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user