Skip to content

Commit

Permalink
add option for multiple services
Browse files Browse the repository at this point in the history
  • Loading branch information
dipinknair committed Jan 29, 2025
1 parent 2dd4235 commit 57e20fe
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/ansys/mechanical/core/embedding/rpc/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 57e20fe

Please sign in to comment.