Example #1
0
def ssl_server(request):
    ssl_server = make_server(addressbook.AddressBookService,
                             Dispatcher(),
                             host='localhost',
                             port=SSL_PORT,
                             certfile="ssl/server.pem")
    ps = multiprocessing.Process(target=ssl_server.serve)
    ps.start()

    time.sleep(0.1)

    def fin():
        if ps.is_alive():
            ps.terminate()

    request.addfinalizer(fin)
Example #2
0
def server(request):
    server = make_server(addressbook.AddressBookService, Dispatcher(),
                         unix_socket=unix_sock)
    ps = multiprocessing.Process(target=server.serve)
    ps.start()

    time.sleep(0.1)

    def fin():
        if ps.is_alive():
            ps.terminate()
        try:
            os.remove(unix_sock)
        except IOError:
            pass

    request.addfinalizer(fin)
Example #3
0
 def do_server():
     server = make_server(service=test_thrift.BarService,
                          handler=Handler(),
                          host='localhost',
                          port=9090)
     server.serve()
Example #4
0
#!/usr/bin/env python3
# -*- coding:utf-8 -*-

# #############################################################################
# File Name   : server.py
# Author      : DaiDai
# Mail        : [email protected]
# Created Time: 三  3/31 14:57:59 2021
# #############################################################################

import thriftpy2

from thriftpy2.rpc import make_server


class Dispatcher(object):
    def ping(self):
        return "pong"


if __name__ == "__main__":
    pingpong_thrift = thriftpy2.load("pingpong.thrift",
                                     module_name="pingpong_thrift")

    server = make_server(pingpong_thrift.PingPong, Dispatcher(), '127.0.0.1',
                         6000)
    server.serve()
Example #5
0
import thriftpy2
addition_thrift = thriftpy2.load("addition.thrift",
                                 module_name="addition_thrift")

from thriftpy2.rpc import make_server


class AdditionServiceHandler:
    def __init__(self):
        self.log = {}

    def add(self, a, b):
        print("Sending the sub a and b")
        return a + b


server = make_server(addition_thrift.AdditionService, AdditionServiceHandler(),
                     '127.0.0.1', 6000)
server.serve()
Example #6
0
def main():
    server = make_server(sc_thrift.SCService, Dispatcher(), '127.0.0.1', 6000)
    print("serving...")

    server.serve()
Example #7
0
    def fetch_all_works(self, uid):
        return json.dumps(kol.fetch_all_video(uid))

    def checkout_user_agent(self):
        return kol.checkout_user_agent()


if sys.platform == 'win32':
    kol_thrift = thriftpy.load(os.path.join(
        PRO_DIR, '.\\dolphin\\service\\douyin\\data\\kol_thrift.thrift'),
                               module_name='kol_thrift_thrift')
else:
    kol_thrift = thriftpy.load(os.path.join(
        PRO_DIR, './dolphin/service/douyin/data/kol_thrift.thrift'),
                               module_name='kol_thrift_thrift')

app = TProcessor(kol_thrift.KolServer, KolDispatcher())
# server = TProcessor(kol_thrift.KolServer, KolDispatcher())
#
if __name__ == '__main__':
    server = make_server(kol_thrift.KolServer,
                         KolDispatcher(),
                         '0.0.0.0',
                         6000,
                         proto_factory=TCyBinaryProtocolFactory(),
                         trans_factory=TCyBufferedTransportFactory())
    server.serve()

    # gunicorn_thrift dolphin.service.douyin.kolserver:app -k thriftpy_sync -b 0.0.0.0:6000 -w 4 --thrift-protocol-factory thriftpy.protocol:TCyBinaryProtocolFactory --thrift-transport-factory thriftpy.transport:TCyBufferedTransportFactory --thrift-client-timeout=5
    # gunicorn_thrift dolphin.service.douyin.kolserver:app --bind 0.0.0.0:7000 -w 10 -k thriftpy_gevent  --timeout 10  --thrift-protocol-factory thriftpy2.protocol:TCyBinaryProtocolFactory --thrift-transport-factory thriftpy2.transport:TCyBufferedTransportFactory --error-logfile aa.log -D -p douyin_server.pid
Example #8
0
def main():
    # 定义监听的端口和服务
    server = make_server(pp_thrift.PingService, Dispatcher(), '127.0.0.1',
                         6000)
    print("serving...")
    server.serve()
Example #9
0
def main():
    server = make_server(tutorial_thrift.Calculator, CalculatorHandler(),
                         '127.0.0.1', 6000)
    print("serving...")
    server.serve()
Example #10
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# FileName  : thrift_server.py
# Author    : wuqingfeng@

import time
import thriftpy2
from thriftpy2.rpc import make_server


class Dispatcher(object):
    def get_time(self):
        return str(time.ctime())


if __name__ == '__main__':

    time_thrift = thriftpy2.load("time_service.thrift", module_name="time_thrift")

    server = make_server(time_thrift.TimeService, Dispatcher(), '127.0.0.1', 6000)
    server.serve()
Example #11
0
def main():
    server = make_server(sleep_thrift.Sleep, Dispatcher(), '127.0.0.1', 6000)
    print("serving...")
    server.serve()
Example #12
0
# -*- coding: utf8 -*-
import thriftpy2
hello_world_thrift = thriftpy2.load("hello_world.thrift",
                                    module_name="hello_world_thrift")

from thriftpy2.rpc import make_server


class Dispatcher(object):
    def call_me(self):
        return "hello world"


server = make_server(hello_world_thrift.HelloWorld, Dispatcher(), '127.0.0.1',
                     6000)
server.serve()
Example #13
0
        created = datetime.datetime.now()
        todos[todo_id] = interfaces.todo.TodoItem(
            id=todo_id,
            text=text,
            type=type,
            created=interfaces.dates.DateTime(
                year=created.year,
                month=created.month,
                day=created.day,
                hour=created.hour,
                minute=created.minute,
                second=created.second,
            ),
            is_deleted=False,
        )
        return todo_id

    def get(self, id: int) -> "TodoItem":
        try:
            return todos[id]
        except KeyError:
            raise interfaces.shared.NotFound

    def ping(self):
        return "pong"


if __name__ == "__main__":
    server = make_server(interfaces.todo.Todo, Dispatcher(), "127.0.0.1", 6000)
    server.serve()
Example #14
0
message_thrift = thriftpy2.load("message.thrift", module_name="message_thrift")


class MessageServiceHandler:
    def ping(self):
        print("ping")

    def sayHello(self):
        print("sayHello")
        return "sayHello return"

    def sendMobileMessage(self, mobile, message):
        print(mobile)
        print(message)
        print("sendMobileMessage")
        return True

    def sendEmailMessage(self, email, message):
        print(email)
        print("sendEmailMessage")
        return True


if __name__ == '__main__':
    # 定义监听的端口和服务
    server = make_server(message_thrift.MessageService,
                         MessageServiceHandler(), '127.0.0.1', 9090)
    print("serving...")
    server.serve()
    print("python thrift server exit")
Example #15
0
def run_server(port):
    make_server(todo_thrift.TodoService, Dispatcher(), "127.0.0.1",
                port).serve()