forked from Sean-Bradley/Seans-gRPC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.py
38 lines (33 loc) · 1.07 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
"""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 % 1000 == 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()