diff --git a/python/grpcdemo_client.py b/python/grpcdemo_client.py deleted file mode 100644 index cf12245..0000000 --- a/python/grpcdemo_client.py +++ /dev/null @@ -1,53 +0,0 @@ -# Example of async call to gRPC server - - -import gc -import grpc -import grpcdemo_pb2 -import grpcdemo_pb2_grpc - -import sys -import time -import tornado.ioloop - -CALL_TIMEOUT = 30 -WAIT_TIME = 10 - - -HOST = sys.argv[1] -PORTNO = 6000 - -ARGS = sys.argv[2:] - - -# Note that in the call logic below, it is the 'future' method that -# makes this async. - -def grpc_call(cmd, callback): - channel = grpc.insecure_channel('%s:%s' % (HOST, PORTNO)) - stub = grpcdemo_pb2_grpc.HostCommandStub(channel) - stub.runcommand.future(grpcdemo_pb2.Command(command=cmd), CALL_TIMEOUT).add_done_callback(callback) - - -# Callback handler - just prints returned string - -def MyCallback(response): - print response.result().cmd_results - - -# Loop over command line args calling remove server -# then wait for answers - -if __name__ == '__main__': - - for cmd in ARGS: - grpc_call(cmd, MyCallback) - print "Called with %s ..." % cmd - gc.collect() # Just to prove rendevous object is still there - -print "Waiting For Response(s)...\n\n" - - -# Nonblocking loop - -tornado.ioloop.IOLoop.instance().start() diff --git a/python/grpcdemo_client_async.py b/python/grpcdemo_client_async.py new file mode 100644 index 0000000..cf12245 --- /dev/null +++ b/python/grpcdemo_client_async.py @@ -0,0 +1,53 @@ +# Example of async call to gRPC server + + +import gc +import grpc +import grpcdemo_pb2 +import grpcdemo_pb2_grpc + +import sys +import time +import tornado.ioloop + +CALL_TIMEOUT = 30 +WAIT_TIME = 10 + + +HOST = sys.argv[1] +PORTNO = 6000 + +ARGS = sys.argv[2:] + + +# Note that in the call logic below, it is the 'future' method that +# makes this async. + +def grpc_call(cmd, callback): + channel = grpc.insecure_channel('%s:%s' % (HOST, PORTNO)) + stub = grpcdemo_pb2_grpc.HostCommandStub(channel) + stub.runcommand.future(grpcdemo_pb2.Command(command=cmd), CALL_TIMEOUT).add_done_callback(callback) + + +# Callback handler - just prints returned string + +def MyCallback(response): + print response.result().cmd_results + + +# Loop over command line args calling remove server +# then wait for answers + +if __name__ == '__main__': + + for cmd in ARGS: + grpc_call(cmd, MyCallback) + print "Called with %s ..." % cmd + gc.collect() # Just to prove rendevous object is still there + +print "Waiting For Response(s)...\n\n" + + +# Nonblocking loop + +tornado.ioloop.IOLoop.instance().start()