Newer
Older
grpcdemo / python / grpcdemo_client.py
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 grpc_call(cmd, callback):
  channel = grpc.insecure_channel('localhost:%s' % PORTNO)
  stub = grpcdemo_pb2_grpc.HostCommandStub(channel)
  stub.runcommand.future(grpcdemo_pb2.Command(command=cmd), CALL_TIMEOUT).add_done_callback(callback)

def MyCallback(response):
  print response.result()

if __name__ == '__main__':

  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()