feat: cd 设置清空缓冲区2

This commit is contained in:
caoqianming 2025-06-23 17:49:02 +08:00
parent c5e4cc48a4
commit b0df18f01a
1 changed files with 20 additions and 15 deletions

View File

@ -7,6 +7,7 @@ from apps.utils.thread import MyThread
import struct
import uuid
import logging
import threading
myLogger = logging.getLogger('log')
@ -133,8 +134,9 @@ def get_tyy_data_2(*args, retry=1):
sc_all = {}
sc_lock = threading.Lock()
def get_tyy_data(*args):
def get_tyy_data(*args, retry=1):
host, port = args[0], int(args[1])
global sc_all
sc = None
@ -151,11 +153,13 @@ def get_tyy_data(*args):
else:
# 清空接收缓冲区
sc.settimeout(0.1) # 设置短暂超时
for _ in range(5):
try:
while True:
sc.recv(1024)
data = sc.recv(65536)
if not data:
break
except (socket.timeout, BlockingIOError):
pass
break
sc.settimeout(5) # 恢复原超时设置
sc.sendall(b"R")
except BrokenPipeError:
@ -195,6 +199,7 @@ def get_tyy_data(*args):
sc = None
raise ParseError(f"采集器连接超时-{str(e)}")
with sc_lock:
connect_and_send()
resp = sc.recv(1024)
res = handle_bytes(resp)