Skip to content
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/3812.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fix: aborting MAPDL
3 changes: 3 additions & 0 deletions src/ansys/mapdl/core/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,9 @@ def handle_generic_grpc_error(
f"Error:\nMAPDL server connection terminated unexpectedly while {msg_}\n"
f"{reason}"
f"{suggestion}"
"MAPDL instance:\n"
f" {mapdl._path}\n"
f" {mapdl.ip}:{mapdl.port}\n"
"Error:\n"
f" {error.details()}\n"
f"Full error:\n{error}"
Expand Down
2 changes: 1 addition & 1 deletion src/ansys/mapdl/core/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -2031,7 +2031,7 @@ def pack_arguments(locals_):
args.update(locals_["kwargs"]) # attaching kwargs

args["set_no_abort"] = locals_.get(
"set_no_abort", locals_["kwargs"].get("set_no_abort", None)
"set_no_abort", locals_["kwargs"].get("set_no_abort", True)
)
args["force_intel"] = locals_.get(
"force_intel", locals_["kwargs"].get("force_intel", None)
Expand Down
2 changes: 1 addition & 1 deletion src/ansys/mapdl/core/mapdl_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,14 @@
"additional_switches",
"check_parameter_names",
"env_vars",
"launched",
"exec_file",
"finish_job_on_exit",
"hostname",
"ip",
"jobid",
"jobname",
"launch_on_hpc",
"launched",
"mode",
"nproc",
"override",
Expand Down
3 changes: 2 additions & 1 deletion src/ansys/mapdl/core/mapdl_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ def __init__(
# Set to not abort after encountering errors. Otherwise, many
# failures in a row will cause MAPDL to exit without returning
# anything useful. Also avoids abort in batch mode if set.
if set_no_abort:
if set_no_abort is None or set_no_abort:
self._set_no_abort()

# double check we have access to the local path if not
Expand Down Expand Up @@ -938,6 +938,7 @@ def _launch(self, start_parm, timeout=10):
@supress_logging
def _set_no_abort(self):
"""Do not abort MAPDL."""
self._log.debug("Setting no abort")
self.nerr(abort=-1, mute=True)

def _run_at_connect(self):
Expand Down
41 changes: 39 additions & 2 deletions tests/test_mapdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@
import psutil
import pytest

from conftest import PATCH_MAPDL_START, VALID_PORTS, Running_test, has_dependency
from conftest import (
PATCH_MAPDL,
PATCH_MAPDL_START,
VALID_PORTS,
Running_test,
has_dependency,
)

if has_dependency("pyvista"):
from pyvista import MultiBlock
Expand Down Expand Up @@ -67,7 +73,6 @@
TEST_FILES = os.path.join(PATH, "test_files")
FIRST_TIME_FILE = os.path.join(USER_DATA_PATH, ".firstime")


if VALID_PORTS:
PORT1 = max(VALID_PORTS) + 1
else:
Expand Down Expand Up @@ -2968,3 +2973,35 @@ def test_muted(mapdl, prop):
assert mapdl.prep7() is None

assert not mapdl.mute


@requires("ansys-tools-path")
@patch(
"ansys.tools.path.path._get_application_path",
lambda *args, **kwargs: "path/to/mapdl/executable",
)
@patch("ansys.tools.path.path._mapdl_version_from_path", lambda *args, **kwargs: 242)
@stack(*PATCH_MAPDL)
@patch("ansys.mapdl.core.Mapdl._exit_mapdl", lambda *args, **kwargs: None)
@pytest.mark.parametrize("set_no_abort", [True, False, None])
@pytest.mark.parametrize("start_instance", [True, False])
def test_set_no_abort(monkeypatch, set_no_abort, start_instance):
monkeypatch.delenv("PYMAPDL_START_INSTANCE", False)

with (
patch(
"ansys.mapdl.core.mapdl_grpc.MapdlGrpc._run", return_value=""
) as mock_run,
patch(
"ansys.mapdl.core.mapdl_grpc.MapdlGrpc.__del__", return_value=None
) as mock_del,
):
mapdl = launch_mapdl(set_no_abort=set_no_abort, start_instance=start_instance)

kwargs = mock_run.call_args_list[0].kwargs
calls = [each.args[0].upper() for each in mock_run.call_args_list]

if set_no_abort is None or set_no_abort:
assert any(["/NERR,,,-1" in each for each in calls])

del mapdl