test01.py
1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import time
from websocket import create_connection
def connect_node(index, ques):
t0 = time.time()
ans = ""
url = f"ws://192.168.3.191:8504/ws/{index}"
ws = create_connection(url)
ws.send(ques)
while True:
try:
recv_text = ws.recv()
print(index, recv_text)
if "<rdfast stop>" in recv_text:
print(
index,
"耗时为:",
round(time.time() - t0, 2),
"s,结果为:",
recv_text,
)
print(index, "break")
break
ans += recv_text
except Exception as e:
print(index, "except: ", str(e))
recv_text = ws.recv()
break
print(index, ans)
ws.close()
def connect_node_01(index, ques):
t0 = time.time()
ans = ""
# url = f"ws://127.0.0.1:8000/ws/{index}"
url = f"ws://127.0.0.1:23456/ws/"
ws = create_connection(url)
ws.send(ques)
while True:
try:
recv_text = ws.recv()
print(index, recv_text)
if "<rdfast stop>" in recv_text:
print(
index,
"耗时为:",
round(time.time() - t0, 2),
"s,结果为:",
recv_text,
)
print(index, "break")
break
ans += recv_text
except Exception as e:
print(index, "except: ", str(e))
recv_text = ws.recv()
break
print(index, ans)
ws.close()
def countdown(n):
while n > 0:
yield n
n -= 1
if __name__ == "__main__":
# connect_node(1,{"question":"你好"})
# connect_node_01(1,{"question":"你好"})
for num in countdown(5):
print(num)
# end main