From 8048e2b5d958d2c926b015ca0b5c8015ef4024ac Mon Sep 17 00:00:00 2001 From: Paul Profizi <100710998+PProfizi@users.noreply.github.com> Date: Fri, 24 Nov 2023 10:35:25 +0100 Subject: [PATCH] Optimize CGrpcServer getters (#1284) * Add ResultInfo._description in result_info.py * Bypass location in available results when LegacyGrpc as it is too slow * Tests on ResultInfo.__str__ skip LegacyGrpc * Cache call to result_info_grpcapi.py list_result * Cache call to result_info_grpcapi.py result_info_get_int_property * Cache call to result_info_grpcapi.py result_info_get_string_property * Cache call to result_info_grpcapi.py list * Revert "Tests on ResultInfo.__str__ skip LegacyGrpc" This reverts commit ff45b25b2d39da5c0c77d123891a23ee60736ebc. * Revert "Bypass location in available results when LegacyGrpc as it is too slow" This reverts commit e9a2888b0cc455c7e982936c3f29a8e1084c117d. * Remove unreachable code * Cache GrpcServer.version and GrpcServer.os * Remove useless import * Remove changes to gate code --- src/ansys/dpf/core/result_info.py | 7 +++++-- src/ansys/dpf/core/server_types.py | 25 +++++++++++++++---------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/ansys/dpf/core/result_info.py b/src/ansys/dpf/core/result_info.py index 6db4a936d2..b950ac32d2 100644 --- a/src/ansys/dpf/core/result_info.py +++ b/src/ansys/dpf/core/result_info.py @@ -144,9 +144,12 @@ def __str__(self): return txt except Exception as e: raise e - from ansys.dpf.core.core import _description - return _description(self._internal_obj, self._server) + @property + def _description(self): + from ansys.dpf.core.core import _description + + return _description(self._internal_obj, self._server) @property def _names(self): diff --git a/src/ansys/dpf/core/server_types.py b/src/ansys/dpf/core/server_types.py index fc100c0c70..1f888d702b 100644 --- a/src/ansys/dpf/core/server_types.py +++ b/src/ansys/dpf/core/server_types.py @@ -678,6 +678,8 @@ def __init__( self._grpc_client_path = load_api.load_grpc_client(ansys_path=ansys_path) self._own_process = launch_server self._local_server = False + self._os = None + self._version = None address = f"{ip}:{port}" @@ -735,21 +737,24 @@ def _check_first_call(self, num_connection_tryouts): @property def version(self): - from ansys.dpf.gate import data_processing_capi, integral_types + if not self._version: + from ansys.dpf.gate import data_processing_capi, integral_types - api = data_processing_capi.DataProcessingCAPI - major = integral_types.MutableInt32() - minor = integral_types.MutableInt32() - api.data_processing_get_server_version_on_client(self.client, major, minor) - out = str(int(major)) + "." + str(int(minor)) - return out + api = data_processing_capi.DataProcessingCAPI + major = integral_types.MutableInt32() + minor = integral_types.MutableInt32() + api.data_processing_get_server_version_on_client(self.client, major, minor) + self._version = str(int(major)) + "." + str(int(minor)) + return self._version @property def os(self): - from ansys.dpf.gate import data_processing_capi + if not self._os: + from ansys.dpf.gate import data_processing_capi - api = data_processing_capi.DataProcessingCAPI - return api.data_processing_get_os_on_client(self.client) + api = data_processing_capi.DataProcessingCAPI + self._os = api.data_processing_get_os_on_client(self.client) + return self._os def _create_shutdown_funcs(self): from ansys.dpf.gate import data_processing_capi