]>
git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/thrift/tutorial/py/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
24 sys
.path
.append('gen-py')
25 sys
.path
.insert(0, glob
.glob('../../lib/py/build/lib*')[0])
27 from tutorial
import Calculator
28 from tutorial
.ttypes
import InvalidOperation
, Operation
, Work
30 from thrift
import Thrift
31 from thrift
.transport
import TSocket
32 from thrift
.transport
import TTransport
33 from thrift
.protocol
import TBinaryProtocol
38 transport
= TSocket
.TSocket('localhost', 9090)
40 # Buffering is critical. Raw sockets are very slow
41 transport
= TTransport
.TBufferedTransport(transport
)
44 protocol
= TBinaryProtocol
.TBinaryProtocol(transport
)
46 # Create a client to use the protocol encoder
47 client
= Calculator
.Client(protocol
)
55 sum_
= client
.add(1, 1)
56 print('1+1=%d' % sum_
)
60 work
.op
= Operation
.DIVIDE
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
)
71 work
.op
= Operation
.SUBTRACT
75 diff
= client
.calculate(1, work
)
76 print('15-10=%d' % diff
)
78 log
= client
.getStruct(1)
79 print('Check log: %s' % log
.value
)
85 if __name__
== '__main__':
88 except Thrift
.TException
as tx
:
89 print('%s' % tx
.message
)