From 9aff86aaaad6d150d1951d37a8f69b8ba3caac68 Mon Sep 17 00:00:00 2001 From: German Date: Wed, 17 Jan 2024 10:54:39 +0100 Subject: [PATCH 1/4] exposing a reconnection method --- src/ansys/mapdl/core/mapdl_grpc.py | 45 ++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/src/ansys/mapdl/core/mapdl_grpc.py b/src/ansys/mapdl/core/mapdl_grpc.py index a0eaba8132..24dd8db606 100644 --- a/src/ansys/mapdl/core/mapdl_grpc.py +++ b/src/ansys/mapdl/core/mapdl_grpc.py @@ -410,18 +410,7 @@ def __init__( if self._mapdl_process: self._create_process_stds_queue() - try: - self._multi_connect(timeout=timeout) - except MapdlConnectionError as err: # pragma: no cover - self._post_mortem_checks() - self._log.debug( - "The error wasn't caught by the post-mortem checks.\nThe stdout is printed now:" - ) - self._log.debug(self._stdout) - - raise err # Raise original error if we couldn't catch it in post-mortem analysis - else: - self._log.debug("Connection established") + self.reconnect_to_mapdl() # Avoiding muting when connecting to the session # It might trigger some errors later on if not. @@ -455,6 +444,38 @@ def __init__( self._create_session() + def _connect_to_mapdl(self, timeout: int): + """(Re)connect to an existing MAPDL instance""" + try: + self._multi_connect(timeout=timeout) + except MapdlConnectionError as err: # pragma: no cover + self._post_mortem_checks() + self._log.debug( + "The error wasn't caught by the post-mortem checks.\nThe stdout is printed now:" + ) + self._log.debug(self._stdout) + + raise err # Raise original error if we couldn't catch it in post-mortem analysis + else: + self._log.debug("Connection established") + + def reconnect_to_mapdl(self, timeout: int = None): + """Reconnect to an already instantiated MAPDL instance. + + Re-establish an stopped or crashed gRPC connection with an already alive + MAPDL instance. This function does not relaunch the MAPDL instance. + + Parameters + ---------- + timeout : int, optional + Timeout before raising an exception, by default None + """ + + if not timeout: + timeout = self._timeout + + self._connect_to_mapdl(timeout) + def _create_process_stds_queue(self, process=None): from ansys.mapdl.core.launcher import ( _create_queue_for_std, # Avoid circular import error From f2cbbb7743c998900d93a76cf7107c0deee2486e Mon Sep 17 00:00:00 2001 From: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com> Date: Tue, 27 May 2025 13:35:19 +0000 Subject: [PATCH 2/4] chore: adding changelog file 3933.miscellaneous.md [dependabot-skip] --- doc/changelog.d/3933.miscellaneous.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 doc/changelog.d/3933.miscellaneous.md diff --git a/doc/changelog.d/3933.miscellaneous.md b/doc/changelog.d/3933.miscellaneous.md new file mode 100644 index 0000000000..5ef85966ac --- /dev/null +++ b/doc/changelog.d/3933.miscellaneous.md @@ -0,0 +1 @@ +exposing a reconnection method \ No newline at end of file From 8c28d73eee902ad1dd5be4ce704cc7c2489c005e Mon Sep 17 00:00:00 2001 From: German <28149841+germa89@users.noreply.github.com> Date: Fri, 30 May 2025 14:23:46 +0200 Subject: [PATCH 3/4] Update src/ansys/mapdl/core/mapdl_grpc.py Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com> --- src/ansys/mapdl/core/mapdl_grpc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ansys/mapdl/core/mapdl_grpc.py b/src/ansys/mapdl/core/mapdl_grpc.py index 94d7c13c23..5871658aa6 100644 --- a/src/ansys/mapdl/core/mapdl_grpc.py +++ b/src/ansys/mapdl/core/mapdl_grpc.py @@ -543,7 +543,7 @@ def reconnect_to_mapdl(self, timeout: int = None): Timeout before raising an exception, by default None """ - if not timeout: + if timeout is None: timeout = self._timeout self._connect_to_mapdl(timeout) From 49a4ff3e975fdf8011e7817064428b7edfb75a99 Mon Sep 17 00:00:00 2001 From: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com> Date: Fri, 30 May 2025 12:26:07 +0000 Subject: [PATCH 4/4] chore: adding changelog file 3933.miscellaneous.md [dependabot-skip] --- doc/changelog.d/3933.miscellaneous.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/changelog.d/3933.miscellaneous.md b/doc/changelog.d/3933.miscellaneous.md index 5ef85966ac..ba2f2974e8 100644 --- a/doc/changelog.d/3933.miscellaneous.md +++ b/doc/changelog.d/3933.miscellaneous.md @@ -1 +1 @@ -exposing a reconnection method \ No newline at end of file +feat: exposing a reconnection method \ No newline at end of file