jina.serve.runtimes.gateway package#



Module contents#

class jina.serve.runtimes.gateway.GatewayRuntime(args, cancel_event=None, **kwargs)[source]#

Bases: AsyncNewLoopRuntime

The Gateway Runtime that starts a gateway pod. The GatewayRuntime is associated with a Gateway class that inherits BaseGateway. While the Gateway class takes care of server and application logic and serving gRPC/HTTP/Websocket API, The GatewayRuntime is responsible of instantiating the right Gateway class, injecting right parameters to it and running/terminating the Gateway object.

async async_setup()[source]#

The async method setup the runtime.

Setup the uvicorn server.

async async_teardown()[source]#

Shutdown the server.

async async_cancel()[source]#

Stop the server.

async async_run_forever()[source]#

Running method of the server.

static is_ready(ctrl_address, protocol='grpc', timeout=1.0, **kwargs)[source]#

Check if status is ready.

  • ctrl_address (str) – the address where the control request needs to be sent

  • protocol (Optional[str]) – protocol of the gateway runtime

  • timeout (float) – timeout of grpc call in seconds

  • kwargs – extra keyword arguments

Return type:



True if status is ready else False.

classmethod wait_for_ready_or_shutdown(timeout, ready_or_shutdown_event, ctrl_address, protocol='grpc', **kwargs)[source]#

Check if the runtime has successfully started

  • timeout (Optional[float]) – The time to wait before readiness or failure is determined

  • ctrl_address (str) – the address where the control message needs to be sent

  • ready_or_shutdown_event (Union[Event, Event]) – the multiprocessing event to detect if the process failed or is ready

  • protocol (Optional[str]) – protocol of the gateway runtime

  • kwargs – extra keyword arguments


True if is ready or it needs to be shutdown


Create a gRPC client aio channel interceptor. :rtype: Optional[Sequence[ClientInterceptor]] :returns: An invocation-side list of aio interceptor objects.


Create a gRPC aio server interceptor. :rtype: Optional[Sequence[ServerInterceptor]] :returns: A service-side aio interceptor object.

async cancel_warmup_task()#

Cancel warmup task if exists and is not completed. Cancellation is required if the Flow is being terminated before the task is successful or hasn’t reached the max timeout.


Running method to block the main thread.

Run the event loop until a Future is done.


Call async_teardown() and stop and close the event loop.

Return type:



a gRPC client interceptor with the global tracing provider.