feat: cd.py清空缓冲区后再执行

This commit is contained in:
caoqianming 2025-07-17 09:45:41 +08:00
parent 17996a0b86
commit 47cfa7ce17
1 changed files with 10 additions and 0 deletions

View File

@ -79,6 +79,16 @@ class JSONRequestHandler(BaseHTTPRequestHandler):
sc.settimeout(5) # 设置超时
sc.connect((host, int(port)))
sc_all[addr] = sc
# 清空接收缓冲区
sc.settimeout(0.1) # 设置短暂超时
for _ in range(5):
try:
data = sc.recv(65536)
if not data:
break
except (socket.timeout, BlockingIOError):
break
sc.settimeout(5) # 恢复原超时设置
sc.sendall(b"R")
return sc
except Exception as e: