feat: cd BrokenPipeError时尝试再建立连接

This commit is contained in:
caoqianming 2025-06-05 11:05:55 +08:00
parent bd9d5a5dc2
commit 370c905781
1 changed files with 8 additions and 1 deletions

View File

@ -22,6 +22,13 @@ def get_tyy_data_t(host, port):
try: try:
sc = socket.socket() sc = socket.socket()
sc.connect((host, int(port))) sc.connect((host, int(port)))
except BrokenPipeError:
try:
sc.close()
except Exception:
pass
sc = socket.socket()
sc.connect((host, int(port)))
except OSError as e: except OSError as e:
cache.set(cd_thread_key, {"err_msg": f"采集器连接失败-{str(e)}"}) cache.set(cd_thread_key, {"err_msg": f"采集器连接失败-{str(e)}"})
except ConnectionResetError: except ConnectionResetError:
@ -52,7 +59,7 @@ def get_tyy_data(*args):
num = 0 num = 0
while True: while True:
num += 1 num += 1
if num > 6: if num > 8:
break break
val = cache.get(cd_thread_key) val = cache.get(cd_thread_key)
if isinstance(val, dict): if isinstance(val, dict):