-
Notifications
You must be signed in to change notification settings - Fork 2
/
client.py
73 lines (66 loc) · 1.95 KB
/
client.py
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 threading
# from concurrent import futures
# import grpc
# import pingpong_pb2_grpc, pingpong_pb2
# import os, time
#
#
# def run():
# counter = 0
# pid = os.getgid()
# with grpc.insecure_channel("localhost:9999") as channel:
# stub = pingpong_pb2_grpc.PingPongServiceStub(channel)
# while True:
# try:
# start = time.time()
# response = stub.ping(pingpong_pb2.Ping(count=counter))
# counter = response.count
#
# if counter % 100:
# print("%4f : resp= %s : procid=%i" % (time.time() - start, response.count, pid))
#
# except KeyboardInterrupt:
# print("KeyboardInterrupt")
# channel.unsubscribe(close)
# exit()
#
#
# def close(channel):
# channel.close()
#
#
# if __name__ == "__main__":
# run()
"""The Python implememntation of seans grpc client"""
import os
import time
import grpc
import pingpong_pb2
import pingpong_pb2_grpc
def run():
"The run method, that sends gRPC conformant messsages to the server"
counter = 0
pid = os.getpid()
with grpc.insecure_channel("localhost:9999") as channel:
stub = pingpong_pb2_grpc.PingPongServiceStub(channel)
while True:
try:
start = time.time()
response = stub.ping(pingpong_pb2.Ping(count=counter))
counter = response.count
if counter % 100 == 0:
print(
"%.4f : resp=%s : procid=%i"
% (time.time() - start, response.count, pid)
)
# counter = 0
time.sleep(0.001)
except KeyboardInterrupt:
print("KeyboardInterrupt")
channel.unsubscribe(close)
exit()
def close(channel):
"Close the channel"
channel.close()
if __name__ == "__main__":
run()