narupa.core.grpc_server module

Module providing a wrapper around the running of GRPC servers.

class narupa.core.grpc_server.GrpcServer(*, address: str, port: int, max_workers=128)

Bases: object

A base class for running GRPC servers that handles the starting and closing of the underlying server.

Parameters:
  • address – The IP address at which to run the server.
  • port – The port on which to run the server.
add_service(service)

Add a gRPC service to this server.

Parameters:service – The gRPC service to add, must have the method to add the gRPC service as the attribute

add_to_server_method.

address

Get the address that this server is or was provided at.

address_and_port

Gets the address and port that the server is or was provided on as a tuple.

Returns:The address and port that the server is or was provided on as a tuple.
close()

Stops the server.

Inheritors of this class should override this method with routines to stop services that are running.

port

Get the port that the server is or was provided on. This is 0 if a port was unable to be chosen.

setup_services()

Inheritors of this class should setup any services they run.

narupa.core.grpc_server.get_requested_port_or_default(port: Optional[int], default: int) → int

Returns the port you asked for, or the default one is port is None.