diff --git a/python/grpcdemo_client.py b/python/grpcdemo_client.py index 0a476a2..f6bc196 100644 --- a/python/grpcdemo_client.py +++ b/python/grpcdemo_client.py @@ -1,26 +1,29 @@ -from __future__ import print_function - +import gc import grpc import grpcdemo_pb2 import grpcdemo_pb2_grpc import sys import time +import tornado.ioloop PORTNO = 6000 CALL_TIMEOUT = 30 WAIT_TIME = 10 -def run(): +def grpc_call(cmd, callback): channel = grpc.insecure_channel('localhost:%s' % PORTNO) stub = grpcdemo_pb2_grpc.HostCommandStub(channel) - response = stub.runcommand.future(grpcdemo_pb2.Command(command=sys.argv[1]), CALL_TIMEOUT) + stub.runcommand.future(grpcdemo_pb2.Command(command=cmd), CALL_TIMEOUT).add_done_callback(callback) - response.add_done_callback(MyCallback) - time.sleep(WAIT_TIME) - -def MyCallback(foo): - print(foo.result()) +def MyCallback(response): + print response.result() if __name__ == '__main__': - run() + + for cmd in ("uname", "uptime", "ls"): + grpc_call(cmd, MyCallback) + print "Called with %s ..." % cmd + gc.collect() # Prove rendevous object is still there + +tornado.ioloop.IOLoop.instance().start()