def serve( cls, uses_with: Optional[Dict] = None, uses_metas: Optional[Dict] = None, uses_requests: Optional[Dict] = None, stop_event: Optional[Union[threading.Event, multiprocessing.Event]] = None, **kwargs, ): """Serve this Executor in a temporary Flow. Useful in testing an Executor in remote settings. :param uses_with: dictionary of parameters to overwrite from the default config's with field :param uses_metas: dictionary of parameters to overwrite from the default config's metas field :param uses_requests: dictionary of parameters to overwrite from the default config's requests field :param stop_event: a threading event or a multiprocessing event that once set will resume the control Flow to main thread. :param kwargs: other kwargs accepted by the Flow, full list can be found `here <https://docs.jina.ai/api/jina.orchestrate.flow.base/>` """ from jina import Flow f = Flow(**kwargs).add( uses=cls, uses_with=uses_with, uses_metas=uses_metas, uses_requests=uses_requests, ) with f: f.block(stop_event)
def test_closing_blocked_flow_from_another_thread_via_flow(): def close_blocked_f(flow): time.sleep(3) flow.close() f = Flow().add() with f: t = threading.Thread(target=close_blocked_f, args=(f, )) t.start() f.block()
def test_closing_blocked_flow_from_another_process_via_event(): ev = multiprocessing.Event() def close_blocked_f(): time.sleep(3) ev.set() f = Flow().add() with f: t = multiprocessing.Process(target=close_blocked_f) t.start() f.block(stop_event=ev)
def test_closing_blocked_flow_from_another_thread_via_event(): ev = threading.Event() def close_blocked_f(): time.sleep(3) ev.set() f = Flow().add() with f: t = threading.Thread(target=close_blocked_f) t.start() f.block(stop_event=ev)
def query_restful(): flow = Flow(workspace="workspace", port_expose=os.environ.get('JINA_PORT', str(45678)))\ .add(uses={"jtype": "ImageCrafter", "with": {"target_size": 96, "img_mean": [0.485, 0.456, 0.406], "img_std": [0.229, 0.224, 0.225]}})\ .add(uses=BigTransferEncoder)\ .add(uses={"jtype": "EmbeddingIndexer", "with": {"index_file_name": "image.json"}, "metas": {"name": "vec_idx"}}, name="vec_idx")\ .add(uses={"jtype": "KeyValueIndexer", "metas": {"name": "kv_idx"}}, name="kv_idx")\ .add(uses={"jtype": "MatchImageReader"}) flow.use_rest_gateway() with flow: flow.block()
def query_restful(): f = Flow().load_config('flow-query.yml') f.use_rest_gateway() with f: f.block()
def main(port_expose): f = Flow(port_expose=port_expose).add(uses=TinyDBIndexer).add( uses=SklearnExecutor) with f: f.block()
def query_restful(): flow = Flow(cors=True).load_config('flows/flow-query.yml') flow.rest_api = True flow.protocol = 'http' with flow: flow.block()
def index_restful(): flow = Flow().load_config('flows/flow-index.yml', override_with={'protocol': 'http'}) with flow: flow.block()