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

Function communicate

tutorial/py.tornado/PythonClient.py:41–99  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

39
40@gen.coroutine
41def communicate():
42 # create client
43 transport = TTornado.TTornadoStreamTransport('localhost', 9090)
44 # open the transport, bail on error
45 try:
46 yield transport.open()
47 print('Transport is opened')
48 except TTransport.TTransportException as ex:
49 logging.error(ex)
50 raise gen.Return()
51
52 pfactory = TBinaryProtocol.TBinaryProtocolFactory()
53 client = Calculator.Client(transport, pfactory)
54
55 # ping
56 yield client.ping()
57 print("ping()")
58
59 # add
60 sum_ = yield client.add(1, 1)
61 print("1 + 1 = {0}".format(sum_))
62
63 # make a oneway call without a callback (schedule the write and continue
64 # without blocking)
65 client.zip()
66 print("zip() without callback")
67
68 # make a oneway call with a callback (we'll wait for the stream write to
69 # complete before continuing)
70 client.zip()
71 print("zip() with callback")
72
73 # calculate 1/0
74 work = Work()
75 work.op = Operation.DIVIDE
76 work.num1 = 1
77 work.num2 = 0
78
79 try:
80 quotient = yield client.calculate(1, work)
81 print("Whoa? You know how to divide by zero ? -> {0}".format(quotient))
82 except InvalidOperation as io:
83 print("InvalidOperation: {0}".format(io))
84
85 # calculate 15-10
86 work.op = Operation.SUBTRACT
87 work.num1 = 15
88 work.num2 = 10
89
90 diff = yield client.calculate(1, work)
91 print("15 - 10 = {0}".format(diff))
92
93 # getStruct
94 log = yield client.getStruct(1)
95 print("Check log: {0}".format(log.value))
96
97 # close the transport
98 client._transport.close()

Callers 6

preReadMethod · 0.85
postReadMethod · 0.85
preWriteMethod · 0.85
postWriteMethod · 0.85
asyncCompleteMethod · 0.85
handlerErrorMethod · 0.85

Calls 8

openMethod · 0.95
errorMethod · 0.80
closeMethod · 0.65
pingMethod · 0.45
addMethod · 0.45
zipMethod · 0.45
calculateMethod · 0.45
getStructMethod · 0.45

Tested by 6

preReadMethod · 0.68
postReadMethod · 0.68
preWriteMethod · 0.68
postWriteMethod · 0.68
asyncCompleteMethod · 0.68
handlerErrorMethod · 0.68