This commit is contained in:
caoqianming 2025-09-17 11:15:17 +08:00
commit f60250bb21
1 changed files with 33 additions and 37 deletions

View File

@ -80,9 +80,7 @@ class JSONRequestHandler(BaseHTTPRequestHandler):
sc = socket.socket() sc = socket.socket()
sc.settimeout(5) sc.settimeout(5)
sc.connect((host, int(port))) sc.connect((host, int(port)))
with sc_lock: # 再次加锁,更新 sc_all
sc_all[addr] = sc sc_all[addr] = sc
sc.settimeout(0.5) sc.settimeout(0.5)
while True: while True:
try: try:
@ -110,10 +108,8 @@ class JSONRequestHandler(BaseHTTPRequestHandler):
sc.close() sc.close()
except Exception: except Exception:
pass pass
with sc_lock: # 加锁,清除无效连接
sc_all[addr] = None sc_all[addr] = None
self.error(f'采集器通信失败: {e}') self.error(f'采集器通信失败: {e}')
print(traceback.format_exc())
return None, None return None, None
sc, resp = connect_and_send() sc, resp = connect_and_send()