本文整理汇总了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
示例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)
示例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.