Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: exit getting frozen if routine is not finished #3617

Merged
merged 7 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
if self._local:
self._cache_pids() # Recache processes

if os.name == "nt":
self._kill_server()
self._exit_mapdl_server()

Check warning on line 1190 in src/ansys/mapdl/core/mapdl_grpc.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/mapdl_grpc.py#L1190

Added line #L1190 was not covered by tests

self._close_process()

self._remove_lock_file(path)
else:
self._kill_server()
self._exit_mapdl_server()

Check warning on line 1196 in src/ansys/mapdl/core/mapdl_grpc.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/mapdl_grpc.py#L1196

Added line #L1196 was not covered by tests

def _remove_temp_dir_on_exit(self, path=None):
"""Removes the temporary directory created by the launcher.
Expand All @@ -1218,7 +1219,7 @@
tmp_dir,
)

def _kill_server(self):
def _exit_mapdl_server(self):
"""Call exit(0) on the server.

Notes
Expand All @@ -1231,14 +1232,18 @@
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:

Check warning on line 1236 in src/ansys/mapdl/core/mapdl_grpc.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/mapdl_grpc.py#L1236

Added line #L1236 was not covered by tests
self._ctrl("EXIT")
else:

elif self._version >= 24.1:

Check warning on line 1239 in src/ansys/mapdl/core/mapdl_grpc.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/mapdl_grpc.py#L1239

Added line #L1239 was not covered by tests
# We can't use the non-cached version because of recursion error.
# self.run("/EXIT,NOSAVE,,,,,SERVER")
self.finish()

Check warning on line 1242 in src/ansys/mapdl/core/mapdl_grpc.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/mapdl_grpc.py#L1242

Added line #L1242 was not covered by tests
self._ctrl("EXIT")

return

Check warning on line 1245 in src/ansys/mapdl/core/mapdl_grpc.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/mapdl_grpc.py#L1245

Added line #L1245 was not covered by tests

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 @@
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
Loading