From 4b26c2963b7954630e800393177e77187f2c13f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?COT001=5C=E6=9D=8E=E6=97=AD=E5=85=89?= <871066422@qq.com> Date: Wed, 18 Mar 2026 18:42:17 +0800 Subject: [PATCH] 127.0.0.1 --- config.json | 4 ++-- frontend/wrench_gui.py | 29 ++++++++++++++++++----------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/config.json b/config.json index 8e75846..4bb4478 100644 --- a/config.json +++ b/config.json @@ -1,6 +1,6 @@ { "api": { - "base_url": "http://localhost:5000", + "base_url": "http://127.0.0.1:5000", "description": "后端API服务地址,例如:http://localhost:5000 或 http://192.168.1.100:5000" }, "wrench": { @@ -21,7 +21,7 @@ "description": "延时配置(秒):wrench_init=扳手初始化延时, param_set=参数设置延时, retry=重试延时, bolt_complete=螺栓完成延时, status_check_interval=状态检测间隔" }, "test_mode": { - "enabled": true, + "enabled": false, "description": "测试模式:失败也算成功,用于无钉子测试" }, "bolt_default_config": { diff --git a/frontend/wrench_gui.py b/frontend/wrench_gui.py index 506bdef..4881359 100644 --- a/frontend/wrench_gui.py +++ b/frontend/wrench_gui.py @@ -55,6 +55,9 @@ class WrenchGUI: self.api_base_url = self.load_api_config() self.poll_interval = 3 # 轮询间隔(秒) + # 创建Session复用连接 + self.session = requests.Session() + # 数据 self.work_order = None self.current_bolt_index = 0 @@ -501,7 +504,7 @@ class WrenchGUI: def load_api_config(self): """从配置文件读取API地址,如果没有则使用默认值""" - default_url = "http://localhost:5000/api" + default_url = "http://127.0.0.1:5000/api" try: config_path = self.get_config_path() if os.path.exists(config_path): @@ -551,8 +554,12 @@ class WrenchGUI: """后台线程查询工单""" try: url = f"{self.api_base_url}/work-orders" - response = requests.get(url, timeout=10) - + import time + + start = time.time() + print("开始查询工单:", time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(start)),self.api_base_url) + response = self.session.get(url, timeout=10) + print("总耗时:", time.time() - start) if response.status_code == 200: data = response.json() if data.get("success"): @@ -659,7 +666,7 @@ class WrenchGUI: while self.is_polling: try: url = f"{self.api_base_url}/work-orders" - response = requests.get(url, timeout=10) + response = self.session.get(url, timeout=10) if response.status_code == 200: data = response.json() @@ -774,7 +781,7 @@ class WrenchGUI: "process_id": process_id, "operator": operator } - response = requests.post(url, json=data, timeout=2) + response = self.session.post(url, json=data, timeout=2) if response.status_code == 200: result = response.json() @@ -823,7 +830,7 @@ class WrenchGUI: try: url = f"{self.api_base_url}/work-orders/unclaim" data = {"trace_id": trace_id, "process_id": process_id} - response = requests.post(url, json=data, timeout=2) + response = self.session.post(url, json=data, timeout=2) if response.status_code == 200: result = response.json() @@ -863,7 +870,7 @@ class WrenchGUI: try: url = f"{self.api_base_url}/work-orders/delete" data = {"trace_id": trace_id, "process_id": process_id} - response = requests.post(url, json=data, timeout=2) + response = self.session.post(url, json=data, timeout=2) if response.status_code == 200: result = response.json() @@ -1203,7 +1210,7 @@ class WrenchGUI: print(f" device_name: {device_name}") print(f" bolts数量: {len(bolt_results)}") - response = requests.post(url, json=data, timeout=10) + response = self.session.post(url, json=data, timeout=10) if response.status_code == 200: result = response.json() @@ -1253,7 +1260,7 @@ class WrenchGUI: """加载扳手设备列表""" try: url = f"{self.api_base_url}/wrench-devices" - response = requests.get(url, timeout=5) + response = self.session.get(url, timeout=5) if response.status_code == 200: data = response.json() @@ -1312,7 +1319,7 @@ class WrenchGUI: try: # 从后端获取设备列表 url = f"{self.api_base_url}/wrench-devices" - response = requests.get(url, timeout=5) + response = self.session.get(url, timeout=5) if response.status_code == 200: data = response.json() @@ -1394,7 +1401,7 @@ def main(): return try: url = f"{app.api_base_url}/work-orders/unclaim" - requests.post(url, json={"trace_id": trace_id, "process_id": process_id}, timeout=1) + app.session.post(url, json={"trace_id": trace_id, "process_id": process_id}, timeout=1) except: pass app.stop_polling()