Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use import extensions #2204

Merged
merged 1 commit into from Mar 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 3 additions & 7 deletions jina/executors/indexers/vector.py
Expand Up @@ -13,6 +13,7 @@
from . import BaseVectorIndexer
from ..decorators import batching
from ...helper import cached_property
from ...importer import ImportExtensions


class BaseNumpyIndexer(BaseVectorIndexer):
Expand Down Expand Up @@ -520,11 +521,6 @@ def _cosine(self, cached_A, raw_B):

@batching(merge_over_axis=1, slice_on=2)
def _cdist(self, *args, **kwargs):
try:
with ImportExtensions(required=True):
from scipy.spatial.distance import cdist

return cdist(*args, **kwargs, metric=self.metric)
except ModuleNotFoundError:
raise ModuleNotFoundError(
f'your metric {self.metric} requires scipy, but scipy is not found'
)
return cdist(*args, **kwargs, metric=self.metric)
19 changes: 10 additions & 9 deletions jina/logging/profile.py
Expand Up @@ -7,11 +7,12 @@
from functools import wraps
from typing import Optional

from ..importer import ImportExtensions
from ..helper import colored, get_readable_size, get_readable_time

if False:
# fix type-hint complain for sphinx and flake
from . import JinaLogger
from ..logging import JinaLogger


def used_memory(unit: int = 1024 * 1024 * 1024) -> float:
Expand All @@ -21,18 +22,18 @@ def used_memory(unit: int = 1024 * 1024 * 1024) -> float:
:param unit: Unit of the memory, default in Gigabytes.
:return: Memory usage of the current process.
"""
try:
with ImportExtensions(required=False):
import resource

return resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / unit
except ModuleNotFoundError:
from . import default_logger

default_logger.error(
'module "resource" can not be found and you are likely running it on Windows, '
'i will return 0'
)
return 0
from . import default_logger

default_logger.error(
'module "resource" can not be found and you are likely running it on Windows, '
'i will return 0'
)
return 0


def used_memory_readable() -> str:
Expand Down