jina.serve.stream package#

Submodules#

Module contents#

class jina.serve.stream.RequestStreamer(request_handler, result_handler, prefetch=0, end_of_iter_handler=None, logger=None, **logger_kwargs)[source]#

Bases: object

A base async request/response streamer.

Parameters:
  • request_handler (Callable[[Request], Awaitable[Request]]) – The callable responsible for handling the request. It should handle a request as input and return a Future to be awaited

  • result_handler (Callable[[Request], Optional[Request]]) – The callable responsible for handling the response.

  • end_of_iter_handler (Optional[Callable[[], None]]) – Optional callable to handle the end of iteration if some special action needs to be taken.

  • prefetch (int) – How many Requests are processed from the Client at the same time.

  • logger (Optional[JinaLogger]) – Optional logger that can be used for logging

  • logger_kwargs – Extra keyword arguments that may be passed to the internal logger constructor if none is provided

async stream(request_iterator, context=None, results_in_order=False, *args)[source]#

stream requests from client iterator and stream responses back.

Parameters:
  • request_iterator – iterator of requests

  • context – context of the grpc call

  • results_in_order (bool) – return the results in the same order as the request_iterator

  • args – positional arguments

Yield:

responses from Executors

Return type:

AsyncIterator[Request]

async wait_floating_requests_end()[source]#

Await this coroutine to make sure that all the floating tasks that the request handler may bring are properly consumed