diff --git a/.ci/start_mapdl.sh b/.ci/start_mapdl.sh index 8d71fa8e02..170f7c0284 100755 --- a/.ci/start_mapdl.sh +++ b/.ci/start_mapdl.sh @@ -14,6 +14,9 @@ docker run \ -p $PYMAPDL_DB_PORT:50055 \ --shm-size=1gb \ -e I_MPI_SHM_LMT=shm \ + --oom-kill-disable \ + --memory=6656MB \ + --memory-swap=16896MB \ $MAPDL_IMAGE \ -$DISTRIBUTED_MODE -np 2 > log.txt & grep -q 'Server listening on' <(timeout 60 tail -f log.txt) diff --git a/.ci/start_mapdl_ubuntu.sh b/.ci/start_mapdl_ubuntu.sh index 2165e2b079..2e3f511dae 100755 --- a/.ci/start_mapdl_ubuntu.sh +++ b/.ci/start_mapdl_ubuntu.sh @@ -17,5 +17,8 @@ docker run \ -e I_MPI_SHM_LMT=shm \ -w /jobs \ -u=0:0 \ + --oom-kill-disable \ + --memory=6656MB \ + --memory-swap=16896MB \ $MAPDL_IMAGE /ansys_inc/v222/ansys/bin/mapdl -grpc -dir /jobs -$DISTRIBUTED_MODE -np 2 > log.txt & grep -q 'Server listening on' <(timeout 60 tail -f log.txt) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c182730ab2..bad8eebe6f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -470,7 +470,7 @@ jobs: commit_long_sha: ${{ steps.attatch-to-pr.outputs.commit_long_sha }} container: image: ghcr.io/ansys/mapdl:v22.2-ubuntu - options: "-u=0:0 --entrypoint /bin/bash" + options: -u=0:0 --oom-kill-disable --memory=6656MB --memory-swap=16896MB --shm-size=1gb --entrypoint /bin/bash credentials: username: ${{ secrets.GH_USERNAME }} password: ${{ secrets.GITHUB_TOKEN }} @@ -596,7 +596,7 @@ jobs: timeout-minutes: 55 container: image: ghcr.io/ansys/mapdl:v22.2-ubuntu - options: "-u=0:0 --entrypoint /bin/bash" + options: -u=0:0 --oom-kill-disable --memory=6656MB --memory-swap=16896MB --shm-size=1gb --entrypoint /bin/bash credentials: username: ${{ secrets.GH_USERNAME }} password: ${{ secrets.GITHUB_TOKEN }} diff --git a/src/ansys/mapdl/core/mapdl.py b/src/ansys/mapdl/core/mapdl.py index 3f89c5e2dd..c64ca5b3b6 100644 --- a/src/ansys/mapdl/core/mapdl.py +++ b/src/ansys/mapdl/core/mapdl.py @@ -826,10 +826,20 @@ def __enter__(self): self._parent()._store_commands = True def __exit__(self, *args): - self._parent()._log.debug("Exiting non-interactive mode") - self._parent()._flush_stored() self._parent()._store_commands = False + if args[0] is not None: + # An exception was raised, let's exit now without flushing + self._parent()._log.debug( + "An exception was found in the `non_interactive` environment. " + "Hence the commands are not flushed." + ) + return None + else: + # No exception so let's flush. + self._parent()._log.debug("Exiting non-interactive mode") + self._parent()._flush_stored() + class _save_selection: """Save the selection and returns to it when exiting""" @@ -3827,7 +3837,20 @@ def get_array( -0.00178402, -0.01234851, 0.01234851, -0.01234851]) """ - arr = self._get_array(entity, entnum, item1, it1num, item2, it2num, kloop) + parm_name = kwargs.get("parm", None) + + if self._store_commands: + raise MapdlRuntimeError( + "Cannot use `mapdl.get_array` when in `non_interactive` mode, " + "since it does not return anything until the `non_interactive` context " + "manager is finished.\n" + "Exit `non_interactive` mode before using this method.\n\n" + "Alternatively you can use `mapdl.vget` to specify the name of the MAPDL parameter where to store the retrieved value." + ) + + arr = self._get_array( + entity, entnum, item1, it1num, item2, it2num, kloop, **kwargs + ) # edge case where corba refuses to return the array ntry = 0 @@ -3853,6 +3876,16 @@ def _get_array( """Uses the VGET command to get an array from ANSYS""" parm_name = kwargs.pop("parm", None) + if self._store_commands and not parm_name: + raise MapdlRuntimeError( + "Cannot use `mapdl._get_array` when in `non_interactive` mode, " + "since it does not return anything until the `non_interactive` context " + "manager is finished.\n" + "Exit `non_interactive` mode before using this method.\n\n" + "Alternatively you can use `mapdl.vget` or use the `parm` kwarg in " + "`mapdl._get_array` to specify the name of the MAPDL parameter where to store the retrieved value. In any case, this function will return `None`" + ) + if parm_name is None: parm_name = "__vget_tmp_%d__" % self._vget_arr_counter self._vget_arr_counter += 1 @@ -3869,6 +3902,10 @@ def _get_array( mute=False, ) + if self._store_commands: + # Return early + return None + # check if empty array if "the dimension number 1 is 0" in out: return np.empty(0) diff --git a/src/ansys/mapdl/core/mapdl_grpc.py b/src/ansys/mapdl/core/mapdl_grpc.py index 3cdf013779..33b6ca9725 100644 --- a/src/ansys/mapdl/core/mapdl_grpc.py +++ b/src/ansys/mapdl/core/mapdl_grpc.py @@ -2040,8 +2040,10 @@ def _get( if self._store_commands: raise MapdlRuntimeError( - "Cannot use gRPC enabled ``GET`` when in non_interactive mode. " - "Exit non_interactive mode before using this method." + "Cannot use `mapdl.get_value` when in `non_interactive` mode. " + "Exit non_interactive mode before using this method.\n\n" + "Alternatively you can use `mapdl.get` to specify the name of " + "the MAPDL parameter where to store the retrieved value.\n" ) cmd = f"{entity},{entnum},{item1},{it1num},{item2},{it2num},{item3}, {it3num}, {item4}, {it4num}" diff --git a/tests/test_mapdl.py b/tests/test_mapdl.py index bab5602e29..e46df07a95 100644 --- a/tests/test_mapdl.py +++ b/tests/test_mapdl.py @@ -2117,3 +2117,10 @@ def test_saving_selection_context(mapdl, cube_solve): assert "nod_selection_4".upper() not in mapdl.cmlist() assert "nod_selection_4" not in mapdl.components + + +def test_get_array_non_interactive(mapdl, solved_box): + mapdl.allsel() + with pytest.raises(MapdlRuntimeError): + with mapdl.non_interactive: + mapdl.get_array("asdf", "2")