当前位置: 首页>>代码示例>>Python>>正文


Python grpc.Server方法代码示例

本文整理汇总了Python中grpc.Server方法的典型用法代码示例。如果您正苦于以下问题:Python grpc.Server方法的具体用法?Python grpc.Server怎么用?Python grpc.Server使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在grpc的用法示例。


在下文中一共展示了grpc.Server方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import grpc [as 别名]
# 或者: from grpc import Server [as 别名]
def __init__(self):
        """Peer는 Radio Station 에 접속하여 leader 및 다른 Peer에 대한 접속 정보를 전달 받는다.

        :return:
        """
        self._peer_id = None
        self._node_key = bytes()
        self.p2p_outer_server: grpc.Server = None
        self._channel_infos = None

        self._peer_target = None
        self._rest_target = None
        self._peer_port = 0

        # gRPC service for Peer
        self._inner_service: PeerInnerService = None
        self._outer_service: PeerOuterService = None

        self._channel_services = {}
        self._rest_service = None

        ObjectManager().peer_service = self 
开发者ID:icon-project,项目名称:loopchain,代码行数:24,代码来源:peer_service.py

示例2: __init__

# 需要导入模块: import grpc [as 别名]
# 或者: from grpc import Server [as 别名]
def __init__(self, broker: str, backend: Optional[str] = None, max_tasks: Optional[int] = None,
                 max_workers: Optional[int] = None):  # pragma: no cover
        """Construct a Clearly Server instance.

        Args:
            broker: the broker being used by the celery system
            backend: the result backend being used by the celery system
            max_tasks: max tasks stored
            max_workers: max workers stored

        """
        max_tasks, max_workers = max_tasks or 10000, max_workers or 100
        logger.info('Creating memory: max_tasks=%d; max_workers=%d', max_tasks, max_workers)
        self._memory = State(max_tasks_in_memory=max_tasks, max_workers_in_memory=max_workers)

        queue_tasks, queue_workers = Queue(), Queue()  # hands new events to be distributed.
        try:
            self._listener = EventListener(broker, queue_tasks, queue_workers,
                                           self._memory, backend)
        except TimeoutError as e:
            logger.critical(e)
            sys.exit(1)

        self._dispatcher_tasks = StreamingDispatcher(queue_tasks, Role.TASKS)
        self._dispatcher_workers = StreamingDispatcher(queue_workers, Role.WORKERS)
        self._rpc = RPCService(self._memory, self._dispatcher_tasks, self._dispatcher_workers) 
开发者ID:rsalmei,项目名称:clearly,代码行数:28,代码来源:server.py

示例3: start_server

# 需要导入模块: import grpc [as 别名]
# 或者: from grpc import Server [as 别名]
def start_server(self, port: int = None, blocking: Optional[bool] = None) \
            -> Optional[grpc.Server]:  # pragma: no cover
        """Start the communication service in a new gRPC server instance.

        Args:
            port: the port clearly server will serve on
            blocking: if True manages gRPC server and blocks the main thread,
                just returns the server otherwise

        Returns:
            the gRPC server if not blocking, None otherwise

        """
        port = port or 12223
        logger.info('Initiating gRPC server: port=%d', port)

        gserver = grpc.server(futures.ThreadPoolExecutor())
        add_ClearlyServerServicer_to_server(self._rpc, gserver)
        gserver.add_insecure_port('[::]:{}'.format(port))

        logger.info('gRPC server ok')
        if blocking is False:
            return gserver

        gserver.start()

        one_day_in_seconds = 24 * 60 * 60
        import time
        try:
            while True:
                time.sleep(one_day_in_seconds)
        except KeyboardInterrupt:
            logger.info('Stopping gRPC server')
            gserver.stop(None)  # immediately. 
开发者ID:rsalmei,项目名称:clearly,代码行数:36,代码来源:server.py


注:本文中的grpc.Server方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。