diff --git a/doc/changelog.d/3617.fixed.md b/doc/changelog.d/3617.fixed.md new file mode 100644 index 0000000000..5b665a9eb3 --- /dev/null +++ b/doc/changelog.d/3617.fixed.md @@ -0,0 +1 @@ +fix: exit getting frozen if routine is not finished \ No newline at end of file diff --git a/src/ansys/mapdl/core/mapdl_grpc.py b/src/ansys/mapdl/core/mapdl_grpc.py index 0ebd1618c3..a0b2cecc66 100644 --- a/src/ansys/mapdl/core/mapdl_grpc.py +++ b/src/ansys/mapdl/core/mapdl_grpc.py @@ -1187,12 +1187,13 @@ def _exit_mapdl(self, path: str = None) -> None: if self._local: self._cache_pids() # Recache processes - if os.name == "nt": - self._kill_server() + self._exit_mapdl_server() + self._close_process() + self._remove_lock_file(path) else: - self._kill_server() + self._exit_mapdl_server() def _remove_temp_dir_on_exit(self, path=None): """Removes the temporary directory created by the launcher. @@ -1218,7 +1219,7 @@ def _remove_temp_dir_on_exit(self, path=None): tmp_dir, ) - def _kill_server(self): + def _exit_mapdl_server(self): """Call exit(0) on the server. Notes @@ -1231,14 +1232,18 @@ def _kill_server(self): if self._exited: return - if ( - self._version and self._version >= 24.2 - ): # We can't use the non-cached version because of recursion error. - # self.run("/EXIT,NOSAVE,,,,,SERVER") + # Default + if self._version is None or self._version < 24.1: self._ctrl("EXIT") - else: + + elif self._version >= 24.1: + # We can't use the non-cached version because of recursion error. + # self.run("/EXIT,NOSAVE,,,,,SERVER") + self.finish() self._ctrl("EXIT") + return + def _kill_process(self): """Kill process stored in self._mapdl_process""" if self._mapdl_process is not None: @@ -1287,15 +1292,12 @@ def _close_process(self, timeout=2): # pragma: no cover Notes ----- This is effectively the only way to completely close down MAPDL locally on - linux. Just killing the server with ``_kill_server`` leaves orphaned + linux. Just killing the server with ``_exit_mapdl_server`` leaves orphaned processes making this method ineffective for a local instance of MAPDL. """ self._log.debug("Closing processes") if self._local: - # killing server process - self._kill_server() - # killing main process (subprocess) self._kill_process()