Example #1
0
def aio_server(request):
    loop = asyncio.new_event_loop()
    server = make_aio_server(addressbook.AddressBookService,
                             Dispatcher(),
                             unix_socket=unix_sock,
                             loop=loop)
    st = threading.Thread(target=server.serve)
    st.daemon = True
    st.start()
    time.sleep(0.1)
Example #2
0
def aio_ssl_server(request):
    loop = asyncio.new_event_loop()
    ssl_server = make_aio_server(
        addressbook.AddressBookService, Dispatcher(),
        host='localhost', port=SSL_PORT,
        certfile="ssl/server.pem", keyfile="ssl/server.key", loop=loop
    )
    st = threading.Thread(target=ssl_server.serve)
    st.daemon = True
    st.start()
    time.sleep(0.1)
Example #3
0
 def _start_server(cls):
     cls.server = make_aio_server(
         addressbook.AddressBookService,
         Dispatcher(),
         trans_factory=cls.TRANSPORT_FACTORY,
         proto_factory=cls.PROTOCOL_FACTORY,
         loop=asyncio.new_event_loop(),
         **cls.server_kwargs(),
     )
     st = threading.Thread(target=cls.server.serve)
     st.daemon = True
     st.start()
     time.sleep(0.1)
Example #4
0
def main():
    server = make_aio_server(echo_thrift.EchoService, Dispatcher(),
                             '127.0.0.1', 6000)
    server.serve()
Example #5
0
import thriftpy2
import asyncio
from thriftpy2.rpc import make_aio_server
import json
import pickle
import datetime
import requests
import time
pingpong_thrift = thriftpy2.load("pingpong.thrift",
                                 module_name="pingpong_thrift")


class Dispatcher(object):
    async def ping(self):
        date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
        print(date)
        await asyncio.sleep(1)
        # res = requests.get(url="http://www.baidu.com")
        # print(res.status_code)
        dic = {"time": date}
        return pickle.dumps(dic)


if __name__ == '__main__':
    server = make_aio_server(pingpong_thrift.PingPong, Dispatcher(),
                             '127.0.0.1', 8000)
    server.serve()