prpc.platform.ws_aiohttp

class prpc.platform.ws_aiohttp.AsyncServer(app, endpoints, ssl_context=None, backlog=None, logger=None, access_log_format=None, shutdown_timeout=None, loop=None)

Starts aiohttp application without blocking the event loop.

Essentially, it is an utility class to get around aiohttp API deficiencies. Mostly inspired by aiohttp.web.run_app, but with some improvements and simplification (e.g. no support for unix domain sockets, oh my).

Can be used as an async context manager (or as a part of one).

Parameters:
  • app – aiohttp.web.Application instance.
  • endpoints – List containing (bound) sockets or pairs (host, port).
  • ssl_context – SSL context (from ssl stdlib module).
  • backlog – Backlog value to use on socket.listen.
  • logger – Logger object to use.
  • access_log_format – Access log format; has some custom format specifiers, please refer to aiohttp docs.
  • shutdown_timeout – Server shutdown timeout.
  • loop – asyncio event loop instance (asyncio.get_event_loop() by default).

Note

Requires some care to implement correct handling of KeyboardInterrupt, as it can essentially happen anywhere.

coroutine start()

Start the server using the configuration from c-tor.

coroutine wait()

Wait until server shutdown. Return immediately if it not running.

coroutine shutdown(timeout=None)

Shutdown the server.

Note

As taken from aiohttp, ‘timeout’ is not really enforced enough. Harsher shutdown mode may be required. You can always just stop the event loop, but peers may get confused a bit.

prpc.platform.ws_aiohttp.make_websocket_factory(session, url, **kwargs)

Create a new websocket factory.

Parameters:
  • session – aiohttp.ClientSession instance.
  • url – Server url (acceptible schemes: http/https/ws/wss).

Note

kwargs are passed directly to aiohttp

coroutine prpc.platform.ws_aiohttp.accept(connection, request, **kwargs)

Accept an incoming connection using aiohttp API.

Parameters:
  • connection – RPC Connection instance.
  • request – aiohttp request.

Note

kwargs are passed directly to connection.accept().

coroutine prpc.platform.ws_aiohttp.connect(connection, url, **kwargs)

Connect to a server using aiohttp API.

Parameters:
  • connection – RPC Connection instance.
  • url – Server url (http/https/ws/wss) or socket factory.

Note

kwargs are passed directly to connection.connect().