narupa.utilities.grpc_utilities module

Utilities for working with GRPC, particularly wrappers with more descriptive names.

exception narupa.utilities.grpc_utilities.RpcAlreadyTerminatedError

Bases: Exception

narupa.utilities.grpc_utilities.subscribe_channel_connectivity_change(channel: grpc.Channel, callback: Callable[[grpc.ChannelConnectivity], None], force_connection: bool = False)

Subscribe to channel connectivity changes with a callback that is called with the channel’s latest connectivity status. Optionally force the channel to begin connecting instead of waiting for an RPC attempt.

Warning

On channel close, all subscriptions are removed without state change.

narupa.utilities.grpc_utilities.subscribe_rpc_termination(context: grpc.RpcContext, callback: Callable[[], None])

Subscribe the termination of an RPC with the given callback.

Raises:RpcAlreadyTerminatedError – if the callback will not be used because termination has already occurred.