From 57e20fe86a8b14f3bae5de38f4dc9224f40a0521 Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Wed, 29 Jan 2025 16:46:38 -0600 Subject: [PATCH 1/3] add option for multiple services --- .../mechanical/core/embedding/rpc/server.py | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/ansys/mechanical/core/embedding/rpc/server.py b/src/ansys/mechanical/core/embedding/rpc/server.py index a067588b8..b83fa29f6 100644 --- a/src/ansys/mechanical/core/embedding/rpc/server.py +++ b/src/ansys/mechanical/core/embedding/rpc/server.py @@ -42,18 +42,23 @@ class MechanicalService(rpyc.Service): """Starts Mechanical app services.""" - def __init__(self, backgroundapp, functions=[], impl=None): + def __init__(self, backgroundapp, functions=[], impl=[]): """Initialize the service.""" super().__init__() self._backgroundapp = backgroundapp self._install_functions(functions) - self._install_class(impl) - self.EMBEDDED = True + self._install_classes(impl) def _install_functions(self, methods): """Install the given list of methods.""" [self._install_function(method) for method in methods] + def _install_classes(self, impl): + """Install the given list of classes.""" + if impl is None: + return + [self._install_class(_impl) for _impl in impl] + def _install_class(self, impl): """Install methods from the given implemented class.""" print("Install class") @@ -224,20 +229,17 @@ def __init__( port: int = None, version: int = None, methods: typing.List[typing.Callable] = [], - impl=None, + impl: typing.List[typing.Callable] = [], ): """Initialize the server.""" self._exited = False self._background_app = BackgroundApp(version=version) self._service = service - self._methods = methods + self._methods = methods if methods is not None else [] print("Initializing Mechanical ...") self._port = self.get_free_port(port) - if impl is None: - self._impl = None - else: - self._impl = impl(self._background_app.app) + self._impl = [i(self._background_app.app) for i in impl] if impl else [] my_service = self._service(self._background_app, self._methods, self._impl) self._server = ThreadedServer(my_service, port=self._port) From 8947fe8ba63ad2146d64b1ab0c06b5c7961162ee Mon Sep 17 00:00:00 2001 From: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com> Date: Wed, 29 Jan 2025 22:50:44 +0000 Subject: [PATCH 2/3] chore: adding changelog file 1074.fixed.md [dependabot-skip] --- doc/changelog.d/1074.fixed.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 doc/changelog.d/1074.fixed.md diff --git a/doc/changelog.d/1074.fixed.md b/doc/changelog.d/1074.fixed.md new file mode 100644 index 000000000..3aa712884 --- /dev/null +++ b/doc/changelog.d/1074.fixed.md @@ -0,0 +1 @@ +Add option on rpc server for accepting multiple services \ No newline at end of file From 780b91044d30b10ca091e25928fdbc30b371d444 Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Wed, 29 Jan 2025 16:56:51 -0600 Subject: [PATCH 3/3] fix conditions --- src/ansys/mechanical/core/embedding/rpc/server.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/ansys/mechanical/core/embedding/rpc/server.py b/src/ansys/mechanical/core/embedding/rpc/server.py index b83fa29f6..f01c6d59d 100644 --- a/src/ansys/mechanical/core/embedding/rpc/server.py +++ b/src/ansys/mechanical/core/embedding/rpc/server.py @@ -51,20 +51,19 @@ def __init__(self, backgroundapp, functions=[], impl=[]): def _install_functions(self, methods): """Install the given list of methods.""" + if not methods: + return [self._install_function(method) for method in methods] def _install_classes(self, impl): """Install the given list of classes.""" - if impl is None: + if not impl: return [self._install_class(_impl) for _impl in impl] def _install_class(self, impl): """Install methods from the given implemented class.""" - print("Install class") - if impl is None: - return - print("Installing methods from class") + print(f"Installing methods from class : {impl}") for methodname, method, methodtype in get_remote_methods(impl): print(f"installing {methodname} of {impl}") if methodtype == MethodType.METHOD: