How to use the grpclib.server.Server function in grpclib

To help you get started, we’ve selected a few grpclib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vmagamedov / grpclib / tests / conn.py View on Github external
async def __aenter__(self):
        host = '127.0.0.1'
        with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
            s.bind(('127.0.0.1', 0))
            _, port = s.getsockname()

        handler = self.handler_cls()
        self.server = server.Server([handler], codec=self.codec)
        await self.server.start(host, port)

        self.channel = client.Channel(host, port, codec=self.codec,
                                      config=self.config)
        stub = self.stub_cls(self.channel)
        return handler, stub
github vmagamedov / grpclib / tests / test_functional.py View on Github external
async def __aenter__(self):
        host = '127.0.0.1'
        with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
            s.bind(('127.0.0.1', 0))
            _, port = s.getsockname()

        dummy_service = DummyService()

        self.server = Server([dummy_service])
        await self.server.start(host, port)

        self.channel = Channel(host=host, port=port)
        dummy_stub = DummyServiceStub(self.channel)
        return dummy_service, dummy_stub
github vmagamedov / grpclib / examples / helloworld / server.py View on Github external
async def main(*, host: str = '127.0.0.1', port: int = 50051) -> None:
    server = Server([Greeter()])
    with graceful_exit([server]):
        await server.start(host, port)
        print(f'Serving on {host}:{port}')
        await server.wait_closed()
github vmagamedov / grpclib / examples / streaming / server.py View on Github external
async def main(*, host: str = '127.0.0.1', port: int = 50051) -> None:
    server = Server([Greeter()])
    with graceful_exit([server]):
        await server.start(host, port)
        print(f'Serving on {host}:{port}')
        await server.wait_closed()
github vmagamedov / grpclib / scripts / bench.py View on Github external
async def _grpclib_server(*, host='127.0.0.1', port=50051):
    server = Server([Greeter()])
    with graceful_exit([server]):
        await server.start(host, port)
        print(f'Serving on {host}:{port}')
        await server.wait_closed()
github vmagamedov / grpclib / examples / tracing / server.py View on Github external
async def main(*, host: str = '127.0.0.1', port: int = 50051) -> None:
    server = Server([Greeter()])
    listen(server, RecvRequest, on_recv_request)
    with graceful_exit([server]):
        await server.start(host, port)
        print(f'Serving on {host}:{port}')
        await server.wait_closed()
github facebook / idb / idb / grpc / server.py View on Github external
#!/usr/bin/env python3
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.

import asyncio
from logging import Logger
from typing import Dict, Optional

from grpclib.server import Server as GRPC_Server
from idb.common.socket import ports_from_sockets
from idb.common.types import Server
from idb.grpc.handler import GRPCHandler
from idb.utils.typing import none_throws


class GRPCServer(GRPC_Server, Server):
    def __init__(self, handler: GRPCHandler, logger: Logger) -> None:
        # pyre-fixme[6]: Expected `Collection[IServable]` for 2nd param but got
        #  `List[GRPCHandler]`.
        GRPC_Server.__init__(self, [handler], loop=asyncio.get_event_loop())
        self.logger = logger

    @property
    def ports(self) -> Dict[str, Optional[int]]:
        # pyre-fixme[6]: Expected `List[socket]` for 1st param but got
        #  `Optional[List[socket]]`.
        (ipv4, ipv6) = ports_from_sockets(none_throws(self._server).sockets)
        return {"ipv4_grpc_port": ipv4, "ipv6_grpc_port": ipv6}
github OlavHN / tfweb / tfweb / tfweb.py View on Github external
})

        get_resource = cors.add(web_app.router.add_resource('/'))
        cors.add(get_resource.add_route("GET", batcher.info_handler))

        post_resource = cors.add(web_app.router.add_resource('/{method}'))
        cors.add(post_resource.add_route("POST", json_handler.handler))

        post_resource = cors.add(web_app.router.add_resource('/'))
        cors.add(post_resource.add_route("POST", json_handler.handler))

    if args.static_path:
        web_app.router.add_static(
                '/web/', path=args.static_path, name='static')

    grpc_app = Server([GrpcHandler(model, batcher)], loop=loop)

    return web_app, grpc_app
github Ehco1996 / aioshadowsocks / shadowsocks / app.py View on Github external
async def start_grpc_server(self):
        from shadowsocks.services import AioShadowsocksServicer

        self.grpc_server = Server([AioShadowsocksServicer()], loop=self.loop)
        await self.grpc_server.start(self.grpc_host, self.grpc_port)
        logging.info(f"Start Grpc Server on {self.grpc_host}:{self.grpc_port}")
github icgood / pymap / pymap / admin / __init__.py View on Github external
def _new_server(cls, backend: BackendInterface, public: bool) -> Server:
        return Server([handler(backend, public) for _, handler in handlers])