Skip to content

Commit 226cb05

Browse files
authored
fix timeout handling (OpenModelica#467)
1. OMSESSION_TIMEOUT - used for OMSession and derived classes 2. MODEL_EXECUTION_TIMEOUT - used for model execution in the default code MODEL_EXECUTION_TIMEOUT = OMSESSION_TIMEOUT if ModelExecutionCmd is called internally
1 parent 8db7387 commit 226cb05

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

OMPython/ModelicaSystem.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
# define logger using the current module name as ID
3838
logger = logging.getLogger(__name__)
3939

40+
MODEL_EXECUTION_TIMEOUT: float = 300.0
41+
4042

4143
class ModelicaSystemError(Exception):
4244
"""
@@ -108,7 +110,7 @@ def __init__(
108110
cmd_prefix: list[str],
109111
cmd_local: bool = False,
110112
cmd_windows: bool = False,
111-
timeout: float = 300.0,
113+
timeout: Optional[float] = None,
112114
model_name: Optional[str] = None,
113115
) -> None:
114116
if model_name is None:
@@ -119,7 +121,13 @@ def __init__(
119121
self._cmd_prefix = cmd_prefix
120122
self._runpath = pathlib.PurePosixPath(runpath)
121123
self._model_name = model_name
122-
self._timeout = timeout
124+
125+
if timeout is None:
126+
# a separate timeout is defined here to allow the use of the class independent of the normal call chain via
127+
# classes derived from OMSession (OMSESSION_TIMEOUT)
128+
self._timeout: float = MODEL_EXECUTION_TIMEOUT
129+
else:
130+
self._timeout = timeout
123131

124132
# dictionaries of command line arguments for the model executable
125133
self._args: dict[str, str | None] = {}
@@ -2830,14 +2838,14 @@ def _prepare_structure_parameters(
28302838

28312839
class ModelicaSystemCmd(ModelExecutionCmd):
28322840
"""
2833-
Compatibility class; in the new version it is renamed as MOdelExecutionCmd.
2841+
Compatibility class; in the new version it is renamed as ModelExecutionCmd.
28342842
"""
28352843

28362844
def __init__(
28372845
self,
28382846
runpath: pathlib.Path,
28392847
modelname: str,
2840-
timeout: float = 300.0,
2848+
timeout: Optional[float] = None,
28412849
) -> None:
28422850
super().__init__(
28432851
runpath=runpath,

OMPython/OMCSession.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
# define logger using the current module name as ID
3636
logger = logging.getLogger(__name__)
3737

38+
OMSESSION_TIMEOUT: float = 300.0
39+
3840

3941
class DockerPopen:
4042
"""
@@ -953,7 +955,7 @@ def __init__(
953955
self.model_execution_local = False
954956

955957
# store variables
956-
self._timeout = 300.0
958+
self._timeout = OMSESSION_TIMEOUT
957959
self.set_timeout(timeout=timeout)
958960
# command prefix (to be used for docker or WSL)
959961
self._cmd_prefix: list[str] = []
@@ -2113,7 +2115,7 @@ class OMSessionRunner(OMSessionRunnerABC):
21132115
def __init__(
21142116
self,
21152117
ompath_runner: Type[OMPathRunnerABC] = OMPathRunnerLocal,
2116-
timeout: float = 10.0,
2118+
timeout: Optional[float] = None,
21172119
version: str = "1.27.0",
21182120
cmd_prefix: Optional[list[str]] = None,
21192121
model_execution_local: bool = True,

0 commit comments

Comments
 (0)