/
server.py
53 lines (34 loc) · 1.29 KB
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python
# coding: utf-8
import config
from modules.log import logsetup, logger
from socket import error as socket_error
import thriftpy
from thriftpy.protocol import TCyBinaryProtocolFactory
from thriftpy.transport import TCyBufferedTransportFactory
from thriftpy.rpc import make_server
from modules.controller import TracesThriftServerController
tracelogs_thrift = thriftpy.load(config.thrift.get('rules'),
module_name=config.thrift.get('module'))
def do_serve(host, port):
print "Starting thrift server on %s:%s..." % (host, port)
try:
server = make_server(
tracelogs_thrift.TraceLogService,
TracesThriftServerController(module=tracelogs_thrift),
host, port,
proto_factory=TCyBinaryProtocolFactory(),
trans_factory=TCyBufferedTransportFactory()
)
server.serve()
except thriftpy.thrift.TException as ex:
logger.error('Thrift error: %s' % ex.message)
except socket_error as sex:
logger.error('Network error: %s' % sex)
except Exception as ex:
logger.error('Application error: %s' % ex)
raise
if __name__ == '__main__':
logsetup()
do_serve(config.thrift.get('host'),
config.thrift.get('port'))