MCPcopy Create free account
hub / github.com/apache/thrift / main

Function main

tutorial/py/PythonClient.py:36–82  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

34
35
36def main():
37 # Make socket
38 transport = TSocket.TSocket('localhost', 9090)
39
40 # Buffering is critical. Raw sockets are very slow
41 transport = TTransport.TBufferedTransport(transport)
42
43 # Wrap in a protocol
44 protocol = TBinaryProtocol.TBinaryProtocol(transport)
45
46 # Create a client to use the protocol encoder
47 client = Calculator.Client(protocol)
48
49 # Connect!
50 transport.open()
51
52 client.ping()
53 print('ping()')
54
55 sum_ = client.add(1, 1)
56 print('1+1=%d' % sum_)
57
58 work = Work()
59
60 work.op = Operation.DIVIDE
61 work.num1 = 1
62 work.num2 = 0
63
64 try:
65 quotient = client.calculate(1, work)
66 print('Whoa? You know how to divide by zero?')
67 print('FYI the answer is %d' % quotient)
68 except InvalidOperation as e:
69 print('InvalidOperation: %r' % e)
70
71 work.op = Operation.SUBTRACT
72 work.num1 = 15
73 work.num2 = 10
74
75 diff = client.calculate(1, work)
76 print('15-10=%d' % diff)
77
78 log = client.getStruct(1)
79 print('Check log: %s' % log.value)
80
81 # Close!
82 transport.close()
83
84
85if __name__ == '__main__':

Callers 1

PythonClient.pyFile · 0.70

Calls 9

openMethod · 0.95
closeMethod · 0.95
TSocketMethod · 0.45
TBufferedTransportMethod · 0.45
TBinaryProtocolMethod · 0.45
pingMethod · 0.45
addMethod · 0.45
calculateMethod · 0.45
getStructMethod · 0.45

Tested by

no test coverage detected