def serve(): server = grpc.server( futures.ThreadPoolExecutor(max_workers=10), interceptors=[ LoggingInterceptor(), MetricInterceptor(), ], ) users_service.add_UsersServicer_to_server(UsersService(), server) # read in key and certificate with open(os.path.join(os.path.split(__file__)[0], 'server.key')) as f: private_key = f.read().encode() with open(os.path.join(os.path.split(__file__)[0], 'server.crt')) as f: certificate_chain = f.read().encode() # create server credentials server_creds = grpc.ssl_server_credentials((( private_key, certificate_chain, ), )) server.add_secure_port('0.0.0.0:50051', server_creds) server.start() try: while True: time.sleep(_ONE_DAY_IN_SECONDS) except KeyboardInterrupt: server.stop(0)
def serve(): server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) users_pb2_grpc.add_UsersServicer_to_server(UsersService(), server) server.add_insecure_port('[::]:22222') server.start() try: while True: time.sleep(_ONE_DAY_IN_SECONDS) except KeyboardInterrupt: server.stop(0)
def serve(): server = grpc.server(ThreadPoolExecutor(max_workers=10)) users_service.add_UsersServicer_to_server(UsersService(), server) server.add_insecure_port('127.0.0.1:50051') server.start() try: while True: time.sleep(_ONE_DAY_IN_SECONDS) except KeyboardInterrupt: server.stop(0)
def serve(): """docstring.""" server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) u_grpc.add_UsersServicer_to_server(Users(), server) server.add_insecure_port('[::]:50051') server.start() try: while True: pass except KeyboardInterrupt: server.stop(0)
def main(): server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) users_pb2_grpc.add_UsersServicer_to_server(UsersService(), server) ip = '127.0.0.1' port = DATA['port'] print('Spartan server started on port {}. . . '.format(port)) server.add_insecure_port('{}:{}'.format(ip, port)) server.start() try: while True: time.sleep(_ONE_DAY_IN_SECONDS_) except KeyboardInterrupt: server.stop(0)
def serve(): server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) users_pb2_grpc.add_UsersServicer_to_server(Users(), server) server.add_insecure_port('[::]:10001') server.start() server.wait_for_termination()
class UsersServicer(users_pb2_grpc.UsersServicer): count = 1 count_stream = 1 def get(self, request, context): print( f'[{datetime.now().strftime("%Y-%m-%d %H:%M:%S")}] #{self.count}') self.count += 1 return users_reply def get_stream(self, request, context): print( f'[{datetime.now().strftime("%Y-%m-%d %H:%M:%S")}] #{self.count_stream}' ) self.count_stream += 1 for i in range(REQUESTS): yield users_reply server = grpc.server(futures.ThreadPoolExecutor(max_workers=1)) users_pb2_grpc.add_UsersServicer_to_server(UsersServicer(), server) server.add_insecure_port('[::]:50051') server.start() print(f'[{datetime.now().strftime("%Y-%m-%d %H:%M:%S")}] GRPC Server START') while True: time.sleep(60)