加固添加设备逻辑。加固iproxy逻辑,加固flask
This commit is contained in:
@@ -34,8 +34,8 @@ class FlaskSubprocessManager:
|
||||
self._monitor_thread: Optional[threading.Thread] = None
|
||||
|
||||
# 看门狗参数
|
||||
self._FAIL_THRESHOLD = int(os.getenv("FLASK_WD_FAIL_THRESHOLD", "3")) # 连续失败多少次重启
|
||||
self._COOLDOWN_SEC = float(os.getenv("FLASK_WD_COOLDOWN", "8.0")) # 两次重启间隔
|
||||
self._FAIL_THRESHOLD = int(os.getenv("FLASK_WD_FAIL_THRESHOLD", "5")) # 连续失败多少次重启
|
||||
self._COOLDOWN_SEC = float(os.getenv("FLASK_WD_COOLDOWN", "10")) # 两次重启间隔
|
||||
self._MAX_RESTARTS = int(os.getenv("FLASK_WD_MAX_RESTARTS", "5")) # 10分钟最多几次重启
|
||||
self._RESTART_WINDOW = 600 # 10分钟
|
||||
self._restart_times: List[float] = []
|
||||
@@ -176,6 +176,15 @@ class FlaskSubprocessManager:
|
||||
|
||||
# ========= 停止 =========
|
||||
def stop(self):
|
||||
with self._lock:
|
||||
if not self.process: return
|
||||
try:
|
||||
if self.process.stdout:
|
||||
self.process.stdout.flush()
|
||||
time.sleep(0.1) # 让读取线程跟上
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
with self._lock:
|
||||
if not self.process:
|
||||
return
|
||||
@@ -253,11 +262,16 @@ class FlaskSubprocessManager:
|
||||
|
||||
# ========= 辅助 =========
|
||||
def _port_alive(self) -> bool:
|
||||
try:
|
||||
with socket.create_connection(("127.0.0.1", self.comm_port), timeout=0.6):
|
||||
return True
|
||||
except Exception:
|
||||
return False
|
||||
def ping(p):
|
||||
try:
|
||||
with socket.create_connection(("127.0.0.1", p), timeout=0.6):
|
||||
return True
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
p1 = self.comm_port
|
||||
p2 = self.comm_port + 1
|
||||
return ping(p1) or ping(p2)
|
||||
|
||||
def _wait_port_open(self, timeout: float) -> bool:
|
||||
start = time.time()
|
||||
|
||||
Reference in New Issue
Block a user