Source

starry / examples / async / async_client.py

Full commit
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from protorpc import messages
from protorpc import remote

from interface import  (SimpleRequest,
                         SimpleResponse,
                         BasicService,
                        )

def client(name='client', address='tcp://0.0.0.0:5000', service_name='basic_service'):
    from starry.transport  import TcpTransport
    basic_service = BasicService.Stub(TcpTransport(name, address, service_name))
    return basic_service

if __name__ == '__main__':
    basic_service = client()
    #print basic_service.transport.ping()
    request = SimpleRequest()
    request.param1 = 'hello, '
    import time
    t1 = time.time()
    print " --------------  async test  ----------------"
    clients = []
    for i in range(10):
        request.param2 = 'world %s'%i
        clients.append(basic_service.async.test(request))
    for i, c in enumerate(clients):
        print i
        print c.response
    t2 = time.time()
    print "tested: ", t2 -t1