From ef92cb1755cc4428ea60b7250cbad51941ff5a86 Mon Sep 17 00:00:00 2001 From: Han Xiao Date: Sat, 9 May 2020 10:20:33 +0200 Subject: [PATCH] style: reformat the code and imports --- docs/chapters/flow/README.md | 15 +++++++++++++-- jina/executors/encoders/frameworks.py | 2 +- jina/executors/encoders/image/paddlehub.py | 1 + jina/executors/encoders/image/tfkeras.py | 2 +- jina/executors/encoders/nlp/farm.py | 2 +- jina/executors/encoders/nlp/flair.py | 2 +- jina/executors/encoders/nlp/paddlehub.py | 2 +- jina/executors/encoders/nlp/transformer.py | 4 ++-- jina/executors/encoders/video/paddlehub.py | 1 - jina/executors/encoders/video/torchvision.py | 1 + jina/executors/indexers/keyvalue/leveldb.py | 1 - jina/executors/indexers/keyvalue/proto.py | 1 - jina/executors/indexers/vector/numpy.py | 1 - 13 files changed, 22 insertions(+), 13 deletions(-) diff --git a/docs/chapters/flow/README.md b/docs/chapters/flow/README.md index ecc03fe9ce2a8..f71f14cd8574b 100644 --- a/docs/chapters/flow/README.md +++ b/docs/chapters/flow/README.md @@ -206,10 +206,21 @@ input_fn = (b's' for _ in range(10)) If you don't use Python as client, or your client and flow are on different instances. You can hold a flow in running state and use client in other languages to connect to it. Simply: +```python +import threading + +with f: + threading.Event().wait() +``` + +Please checkout https://github.com/jina-ai/examples/tree/master/helloword-in-cs for a complete example. + +**WARNING**: don't use while loop to do the waiting, it is extremely low-efficient: + ```python with f: - while True: - pass + while True: # <- dont do that + pass # <- dont do that ``` ## Use Flow API in YAML diff --git a/jina/executors/encoders/frameworks.py b/jina/executors/encoders/frameworks.py index 10efefb44149a..7185017756100 100644 --- a/jina/executors/encoders/frameworks.py +++ b/jina/executors/encoders/frameworks.py @@ -7,7 +7,7 @@ from . import BaseEncoder from ..decorators import batching, as_ndarray -from ..frameworks import BaseOnnxExecutor, BasePaddleExecutor, BaseTorchExecutor, BaseTFExecutor, BaseFrameworkExecutor +from ..frameworks import BaseOnnxExecutor, BasePaddleExecutor, BaseTorchExecutor, BaseTFExecutor from ...helper import is_url diff --git a/jina/executors/encoders/image/paddlehub.py b/jina/executors/encoders/image/paddlehub.py index 4b94b8fc1f30e..bd29ba9e47be4 100644 --- a/jina/executors/encoders/image/paddlehub.py +++ b/jina/executors/encoders/image/paddlehub.py @@ -11,6 +11,7 @@ class ImagePaddlehubEncoder(BaseCVPaddlehubEncoder): Internally, :class:`ImagePaddlehubEncoder` wraps the models from `paddlehub`. https://github.com/PaddlePaddle/PaddleHub """ + def __init__(self, *args, **kwargs): """ diff --git a/jina/executors/encoders/image/tfkeras.py b/jina/executors/encoders/image/tfkeras.py index 0ff715d8d52cf..5df5263f721cc 100644 --- a/jina/executors/encoders/image/tfkeras.py +++ b/jina/executors/encoders/image/tfkeras.py @@ -3,8 +3,8 @@ import numpy as np -from ...decorators import batching, as_ndarray from ..frameworks import BaseCVTFEncoder +from ...decorators import batching, as_ndarray class KerasImageEncoder(BaseCVTFEncoder): diff --git a/jina/executors/encoders/nlp/farm.py b/jina/executors/encoders/nlp/farm.py index 74a2686d90105..cf823e7f9d602 100644 --- a/jina/executors/encoders/nlp/farm.py +++ b/jina/executors/encoders/nlp/farm.py @@ -3,8 +3,8 @@ import numpy as np -from ...decorators import batching, as_ndarray from ..frameworks import BaseTextTorchEncoder +from ...decorators import batching, as_ndarray class FarmTextEncoder(BaseTextTorchEncoder): diff --git a/jina/executors/encoders/nlp/flair.py b/jina/executors/encoders/nlp/flair.py index da6bdf2401ea7..c7be100e324fd 100644 --- a/jina/executors/encoders/nlp/flair.py +++ b/jina/executors/encoders/nlp/flair.py @@ -5,8 +5,8 @@ import numpy as np -from ...decorators import batching, as_ndarray from ..frameworks import BaseTextTorchEncoder +from ...decorators import batching, as_ndarray class FlairTextEncoder(BaseTextTorchEncoder): diff --git a/jina/executors/encoders/nlp/paddlehub.py b/jina/executors/encoders/nlp/paddlehub.py index 1f0b7d15a9267..9fe6156300bde 100644 --- a/jina/executors/encoders/nlp/paddlehub.py +++ b/jina/executors/encoders/nlp/paddlehub.py @@ -3,8 +3,8 @@ import numpy as np -from ...decorators import batching, as_ndarray from ..frameworks import BaseTextPaddlehubEncoder +from ...decorators import batching, as_ndarray class TextPaddlehubEncoder(BaseTextPaddlehubEncoder): diff --git a/jina/executors/encoders/nlp/transformer.py b/jina/executors/encoders/nlp/transformer.py index c0ffe10d620c4..90ad965c4272f 100644 --- a/jina/executors/encoders/nlp/transformer.py +++ b/jina/executors/encoders/nlp/transformer.py @@ -5,10 +5,10 @@ import numpy as np +from .. import BaseEncoder +from ..frameworks import BaseTextTFEncoder, BaseTextTorchEncoder from ..helper import reduce_mean, reduce_max, reduce_min, reduce_cls from ...decorators import batching, as_ndarray -from ..frameworks import BaseTextTFEncoder, BaseTextTorchEncoder -from .. import BaseEncoder class BaseTransformerEncoder(BaseEncoder): diff --git a/jina/executors/encoders/video/paddlehub.py b/jina/executors/encoders/video/paddlehub.py index c8446d384d60d..380983846a080 100644 --- a/jina/executors/encoders/video/paddlehub.py +++ b/jina/executors/encoders/video/paddlehub.py @@ -1,7 +1,6 @@ __copyright__ = "Copyright (c) 2020 Jina AI Limited. All rights reserved." __license__ = "Apache-2.0" - from ..frameworks import BaseCVPaddlehubEncoder diff --git a/jina/executors/encoders/video/torchvision.py b/jina/executors/encoders/video/torchvision.py index 9b1111458249c..a83e47b717602 100644 --- a/jina/executors/encoders/video/torchvision.py +++ b/jina/executors/encoders/video/torchvision.py @@ -12,6 +12,7 @@ class VideoTorchEncoder(BaseCVTorchEncoder, BaseVideoEncoder): Internally, :class:`VideoTorchEncoder` wraps the models from `torchvision.models`. https://pytorch.org/docs/stable/torchvision/models.html """ + def __init__(self, *args, **kwargs): """ diff --git a/jina/executors/indexers/keyvalue/leveldb.py b/jina/executors/indexers/keyvalue/leveldb.py index c0c417743a126..9b3df24fdc151 100644 --- a/jina/executors/indexers/keyvalue/leveldb.py +++ b/jina/executors/indexers/keyvalue/leveldb.py @@ -5,7 +5,6 @@ from typing import Union from google.protobuf.json_format import Parse - from jina.executors.indexers.keyvalue.proto import BasePbIndexer from jina.executors.indexers.keyvalue.proto import jina_pb2 diff --git a/jina/executors/indexers/keyvalue/proto.py b/jina/executors/indexers/keyvalue/proto.py index 36a631ce4cbe4..e45a07d82d5f1 100644 --- a/jina/executors/indexers/keyvalue/proto.py +++ b/jina/executors/indexers/keyvalue/proto.py @@ -6,7 +6,6 @@ from typing import Union from google.protobuf.json_format import Parse - from jina.executors.indexers import BaseKVIndexer from jina.proto import jina_pb2 diff --git a/jina/executors/indexers/vector/numpy.py b/jina/executors/indexers/vector/numpy.py index 0c5a34fe7c89c..bfb64422e903b 100644 --- a/jina/executors/indexers/vector/numpy.py +++ b/jina/executors/indexers/vector/numpy.py @@ -5,7 +5,6 @@ from typing import Tuple, Optional import numpy as np - from jina.executors.indexers import BaseVectorIndexer