feat: auto-reconnect AGV on Flask startup (async, 2s delay)
This commit is contained in:
@@ -118,6 +118,20 @@ try:
|
||||
# Flask 2.3+ 方式
|
||||
with app.app_context():
|
||||
load_persisted_config()
|
||||
# 启动时自动重连 AGV(异步,不阻塞 Flask 启动)
|
||||
import threading
|
||||
def _auto_reconnect():
|
||||
time.sleep(2) # 等待 Flask 完全就绪
|
||||
try:
|
||||
from utils.agv_controller_ros2 import AGVController
|
||||
gs.agv_controller = AGVController()
|
||||
if gs.agv_controller.connect():
|
||||
print("[启动] AGV 自动连接成功")
|
||||
else:
|
||||
print("[启动] AGV 自动连接失败,请手动连接")
|
||||
except Exception as e:
|
||||
print(f"[启动] AGV 自动连接异常: {e}")
|
||||
threading.Thread(target=_auto_reconnect, daemon=True).start()
|
||||
except:
|
||||
# 兼容旧版 Flask
|
||||
@app.before_first_request
|
||||
|
||||
Reference in New Issue
Block a user