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/4221.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add STATUS enum for MAPDL state management
17 changes: 12 additions & 5 deletions src/ansys/mapdl/core/mapdl_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

"""Module to control interaction with MAPDL through Python"""

from enum import Enum
from functools import wraps
import glob
import logging
Expand Down Expand Up @@ -233,6 +234,12 @@
]


class STATUS(str, Enum):
EXITED = "exited"
EXITING = "exiting"
RUNNING = "running"


def parse_to_short_cmd(command):
"""Takes any MAPDL command and returns the first 4 characters of
the command
Expand Down Expand Up @@ -472,18 +479,18 @@ def chain_commands(self):
return self._chain_commands(self)

@property
def check_status(self):
def check_status(self) -> STATUS:
"""Return MAPDL status.
* 'exited' if MAPDL is exited
* 'exiting' if MAPDL is exiting
* Otherwise returns 'OK'.
* Otherwise returns 'running'.
"""
if self.exited:
return "exited"
return STATUS.EXITED
elif self.exiting:
return "exiting"
return STATUS.EXITING
else:
return "OK"
return STATUS.RUNNING

@property
def components(self) -> "ComponentManager":
Expand Down
2 changes: 1 addition & 1 deletion tests/test_mapdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2254,7 +2254,7 @@ def test_exiting(mapdl, cleared):


def test_check_status(mapdl, cleared):
assert mapdl.check_status == "OK"
assert mapdl.check_status == "running"

mapdl._exited = True
assert mapdl.exited
Expand Down
Loading