Skip to content

Commit

Permalink
fix: exit getting frozen if routine is not finished (#3617)
Browse files Browse the repository at this point in the history
* fix: ending routine and going into verify mode when exiting. Also change function name

* docs: better comment

* chore: adding changelog file 3617.fixed.md [dependabot-skip]

* refactor: not issuing verify anymore

* refactor: _exit_mapdl_server branching

* refactor: finishing routine for v24.1 or older

---------

Co-authored-by: pyansys-ci-bot <[email protected]>
  • Loading branch information
germa89 and pyansys-ci-bot authored Dec 12, 2024
1 parent 0ef6161 commit 1473bdd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
1 change: 1 addition & 0 deletions doc/changelog.d/3617.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fix: exit getting frozen if routine is not finished
28 changes: 15 additions & 13 deletions src/ansys/mapdl/core/mapdl_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit 1473bdd

Please sign in to comment.