def index(request): # Make socket transport = TSocket.TSocket('localhost', 9988) # Buffering is critical. Raw sockets are very slow transport = TTransport.TBufferedTransport(transport) # Wrap in a protocol protocol = TBinaryProtocol.TBinaryProtocol(transport) # Create a client to use the protocol encoder processor = TMultiplexedProtocol(protocol, 'PERSON_SERVICE') client = PersonService.Client(processor) # Connect! transport.open() person = Person() person.name = 'name1' person.passwod = 'pwd' person.age = 12121212 psr = client.getPerson(person) dt = time.time() transport.close() return render_to_response('index.html', locals())
# Buffering is critical. Raw sockets are very slow transport = TTransport.TBufferedTransport(transport) # Wrap in a protocol protocol = TBinaryProtocol.TBinaryProtocol(transport) # Create a client to use the protocol encoder client = PersonService.Client(protocol) # Connect! transport.open() sum = client.getValue() print(sum) person = Person() person.name = "name1" person.passwod = "pwd" person.age = 12121212 p = client.getPerson(person) print(p) # Close! transport.close() except Thrift.TException as tx: print("%s" % (tx.message))