舍弃flask。请求增加H2协议。
This commit is contained in:
@@ -59,7 +59,7 @@ class FlaskSubprocessManager:
|
||||
self._log("info", "FlaskSubprocessManager 初始化完成")
|
||||
|
||||
# ========= 日志工具 =========
|
||||
def _log(self, level: str, msg: str, udid="system"):
|
||||
def _log(self, level: str, msg: str, udid="flask"):
|
||||
"""同时写 LogManager + 控制台"""
|
||||
try:
|
||||
if level == "info":
|
||||
@@ -146,6 +146,12 @@ class FlaskSubprocessManager:
|
||||
threading.Thread(target=self._flush_stdout, daemon=True).start()
|
||||
self._log("info", f"[FlaskMgr] Flask 子进程已启动,PID={self.process.pid}")
|
||||
|
||||
# 启动看门狗线程
|
||||
self._watchdog_thread = threading.Thread(target=self.watchdog_loop, daemon=True)
|
||||
self._watchdog_thread.start()
|
||||
|
||||
LogManager.info("[FlaskWD] 看门狗线程已启动", udid="flask")
|
||||
|
||||
if not self._wait_port_open(timeout=10):
|
||||
self._log("error", "[FlaskMgr] 启动失败,端口未监听")
|
||||
self.stop()
|
||||
@@ -292,4 +298,18 @@ class FlaskSubprocessManager:
|
||||
|
||||
@classmethod
|
||||
def get_instance(cls) -> 'FlaskSubprocessManager':
|
||||
return cls()
|
||||
return cls()
|
||||
|
||||
def watchdog_loop(self):
|
||||
while True:
|
||||
if self.process is not None:
|
||||
code = self.process.poll()
|
||||
if code is not None:
|
||||
LogManager.error(
|
||||
text=f"[FlaskWD] Flask 子进程退出,exit code={code}",
|
||||
udid="flask",
|
||||
)
|
||||
# 可以顺便触发一下 _stop_event,看你愿不愿意
|
||||
# self._stop_event.set()
|
||||
break
|
||||
time.sleep(1)
|
||||
Reference in New Issue
Block a user