示例#1
0
文件: __init__.py 项目: dmig/xpostr
def init():
    for m in (common, connections, tg, vk):
        for fn in m.__dict__:
            if not hasattr(m.__dict__[fn],
                           "__call__") or not fn.startswith('handle_'):
                continue

            register(fn[7:], m.__dict__[fn])

    msgpack_init(pack_params=pack_params, unpack_params=unpack_params)
示例#2
0
def run_sum_server():
    def sum(x, y):
        return x + y

    aiorpc.register('sum', sum)
    loop = uvloop.new_event_loop()
    asyncio.set_event_loop(loop)
    coro = asyncio.start_server(aiorpc.serve, 'localhost', 6000, loop=loop)
    loop.run_until_complete(coro)
    loop.run_forever()
示例#3
0
def run_sum_server():
    def sum(x, y):
        return x + y

    aiorpc.register('sum', sum)
    loop = uvloop.new_event_loop()
    asyncio.set_event_loop(loop)
    coro = asyncio.start_unix_server(aiorpc.serve,
                                     './benchmark.socket',
                                     loop=loop)
    loop.run_until_complete(coro)
    loop.run_forever()
示例#4
0
def run_server():
    # asyncio.set_event_loop(asyncio.ProactorEventLoop())
    register("echo", echo)
    register('echo_stream', echo_stream)
    coro = asyncio.start_server(serve, '127.0.0.1', 6000)
    server = asyncio.get_event_loop().run_until_complete(coro)

    old_close = server.close

    def new_close():
        import traceback
        traceback.print_stack()
        old_close()

    server.close = new_close
    old_wait_closed = server.wait_closed

    async def new_wait_closed():
        import traceback
        traceback.print_stack()
        await old_wait_closed()

    server.wait_closed = new_wait_closed

    try:
        while True:
            asyncio.get_event_loop().run_until_complete(asyncio.sleep(10))
            print(server)
        # asyncio.get_event_loop().run_forever()
    except KeyboardInterrupt:
        import objgraph
        objgraph.show_most_common_types(limit=50)
        import gc
        gc.set_debug(gc.DEBUG_LEAK)
        print('=' * 10)
        print(gc.garbage)
        server.close()
        asyncio.get_event_loop().run_until_complete(server.wait_closed())
示例#5
0
文件: test_rpc.py 项目: pyneda/aiorpc
def set_up_server():
    global loop, server
    loop = uvloop.new_event_loop()
    asyncio.set_event_loop(loop)
    register('echo', echo)
    register('echo_delayed', echo_delayed)
    register('raise_error', raise_error)
    coro = asyncio.start_server(serve, HOST, PORT)
    server = loop.run_until_complete(coro)
示例#6
0
def register_handlers():
    register('echo', echo)
    register('echo_delayed', echo_delayed)
    register('raise_error', raise_error)
    register_class(my_class)
示例#7
0
from aiorpc import register, serve

import asyncio
import uvloop


def echo(msg):
    return msg


loop = uvloop.new_event_loop()
asyncio.set_event_loop(loop)
register("echo", echo)
coro = asyncio.start_server(serve, '127.0.0.1', 6000, loop=loop)
server = loop.run_until_complete(coro)

try:
    loop.run_forever()
except KeyboardInterrupt:
    server.close()
    loop.run_until_complete(server.wait_closed())