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)
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()
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()
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())
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)
def register_handlers(): register('echo', echo) register('echo_delayed', echo_delayed) register('raise_error', raise_error) register_class(my_class)
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())