]>
git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/thrift/tutorial/py.tornado/PythonClient.py
4 # Licensed to the Apache Software Foundation (ASF) under one
5 # or more contributor license agreements. See the NOTICE file
6 # distributed with this work for additional information
7 # regarding copyright ownership. The ASF licenses this file
8 # to you under the Apache License, Version 2.0 (the
9 # "License"); you may not use this file except in compliance
10 # with the License. You may obtain a copy of the License at
12 # http://www.apache.org/licenses/LICENSE-2.0
14 # Unless required by applicable law or agreed to in writing,
15 # software distributed under the License is distributed on an
16 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 # KIND, either express or implied. See the License for the
18 # specific language governing permissions and limitations
26 sys
.path
.append('gen-py.tornado')
27 sys
.path
.insert(0, glob
.glob('../../lib/py/build/lib*')[0])
29 from tutorial
import Calculator
30 from tutorial
.ttypes
import Operation
, Work
, InvalidOperation
32 from thrift
import TTornado
33 from thrift
.transport
import TTransport
34 from thrift
.protocol
import TBinaryProtocol
36 from tornado
import gen
37 from tornado
import ioloop
43 transport
= TTornado
.TTornadoStreamTransport('localhost', 9090)
44 # open the transport, bail on error
46 yield transport
.open()
47 print('Transport is opened')
48 except TTransport
.TTransportException
as ex
:
52 pfactory
= TBinaryProtocol
.TBinaryProtocolFactory()
53 client
= Calculator
.Client(transport
, pfactory
)
60 sum_
= yield client
.add(1, 1)
61 print("1 + 1 = {0}".format(sum_
))
63 # make a oneway call without a callback (schedule the write and continue
66 print("zip() without callback")
68 # make a oneway call with a callback (we'll wait for the stream write to
69 # complete before continuing)
71 print("zip() with callback")
75 work
.op
= Operation
.DIVIDE
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
))
86 work
.op
= Operation
.SUBTRACT
90 diff
= yield client
.calculate(1, work
)
91 print("15 - 10 = {0}".format(diff
))
94 log
= yield client
.getStruct(1)
95 print("Check log: {0}".format(log
.value
))
98 client
._transport
.close()
103 # create an ioloop, do the above, then stop
104 ioloop
.IOLoop
.current().run_sync(communicate
)
107 if __name__
== "__main__":