Skip to content
Open
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
3 changes: 3 additions & 0 deletions OMPython/ModelicaSystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ def check_model_executable(self):
cmd_local=self._session.model_execution_local,
cmd_windows=self._session.model_execution_windows,
cmd_prefix=self._session.model_execution_prefix(cwd=self.getWorkDirectory()),
timeout=self._session.set_timeout(),
model_name=self._model_name,
)
# ... by running it - output help for command help
Expand Down Expand Up @@ -901,6 +902,7 @@ def simulate_cmd(
cmd_local=self._session.model_execution_local,
cmd_windows=self._session.model_execution_windows,
cmd_prefix=self._session.model_execution_prefix(cwd=self.getWorkDirectory()),
timeout=self._session.set_timeout(),
model_name=self._model_name,
)

Expand Down Expand Up @@ -1393,6 +1395,7 @@ def linearize(
cmd_local=self._session.model_execution_local,
cmd_windows=self._session.model_execution_windows,
cmd_prefix=self._session.model_execution_prefix(cwd=self.getWorkDirectory()),
timeout=self._session.set_timeout(),
model_name=self._model_name,
)

Expand Down
43 changes: 22 additions & 21 deletions OMPython/OMCSession.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ def run(self) -> int:

cmdl = self.get_cmd()

logger.debug("Run OM command %s in %s", repr(cmdl), self.cmd_path)
logger.debug("Run OM command %s in %s (timeout=%2fs)", repr(cmdl), self.cmd_path, self.cmd_timeout)
try:
cmdres = subprocess.run(
cmdl,
Expand All @@ -702,7 +702,8 @@ def run(self) -> int:
if stderr:
raise ModelExecutionException(f"Error running model executable {repr(cmdl)}: {stderr}")
except subprocess.TimeoutExpired as ex:
raise ModelExecutionException(f"Timeout running model executable {repr(cmdl)}: {ex}") from ex
raise ModelExecutionException("OMPython timeout running model executable "
f"(timeout={self.cmd_timeout:.2f}s){repr(cmdl)}: {ex}") from ex
except subprocess.CalledProcessError as ex:
raise ModelExecutionException(f"Error running model executable {repr(cmdl)}: {ex}") from ex

Expand Down Expand Up @@ -774,6 +775,19 @@ def __post_init__(self) -> None:
Post initialisation method.
"""

def set_timeout(self, timeout: Optional[float] = None) -> float:
"""
Set the timeout to be used for OMC communication (OMCSession).

The defined value is set and the current value is returned. If None is provided as argument, nothing is changed.
"""
retval = self._timeout
if timeout is not None:
if timeout <= 0.0:
raise OMCSessionException(f"Invalid timeout value: {timeout}!")
self._timeout = timeout
return retval

def get_cmd_prefix(self) -> list[str]:
"""
Get session definition used for this instance of OMPath.
Expand Down Expand Up @@ -982,19 +996,6 @@ def _timeout_loop(
yield True
yield False

def set_timeout(self, timeout: Optional[float] = None) -> float:
"""
Set the timeout to be used for OMC communication (OMCSession).

The defined value is set and the current value is returned. If None is provided as argument, nothing is changed.
"""
retval = self._timeout
if timeout is not None:
if timeout <= 0.0:
raise OMCSessionException(f"Invalid timeout value: {timeout}!")
self._timeout = timeout
return retval

@staticmethod
def escape_str(value: str) -> str:
"""
Expand Down Expand Up @@ -1109,7 +1110,7 @@ def sendExpression(self, expr: str, parsed: bool = True) -> Any:
log_content = 'log not available'

logger.error(f"OMC did not start. Log-file says:\n{log_content}")
raise OMCSessionException(f"No connection with OMC (timeout={self._timeout}).")
raise OMCSessionException(f"No connection with OMC (timeout={self._timeout:.2f}s).")

if expr == "quit()":
self._omc_zmq.close()
Expand Down Expand Up @@ -1335,7 +1336,7 @@ def _omc_port_get(self) -> str:
break
else:
logger.error(f"OMC server did not start. Log-file says:\n{self.get_log()}")
raise OMCSessionException(f"OMC Server did not start (timeout={self._timeout}, "
raise OMCSessionException(f"OMC Server did not start (timeout={self._timeout:.2f}s, "
f"logfile={repr(self._omc_logfile)}).")

logger.info(f"Local OMC Server is up and running at ZMQ port {port} "
Expand Down Expand Up @@ -1462,7 +1463,7 @@ def _docker_process_get(self, docker_cid: str) -> Optional[DockerPopen]:
break
else:
logger.error(f"Docker did not start. Log-file says:\n{self.get_log()}")
raise OMCSessionException(f"Docker based OMC Server did not start (timeout={self._timeout}).")
raise OMCSessionException(f"Docker based OMC Server did not start (timeout={self._timeout:.2f}s).")

return docker_process

Expand Down Expand Up @@ -1500,7 +1501,7 @@ def _omc_port_get(self) -> str:
break
else:
logger.error(f"Docker did not start. Log-file says:\n{self.get_log()}")
raise OMCSessionException(f"Docker based OMC Server did not start (timeout={self._timeout}, "
raise OMCSessionException(f"Docker based OMC Server did not start (timeout={self._timeout:.2f}s, "
f"logfile={repr(self._omc_logfile)}).")

logger.info(f"Docker based OMC Server is up and running at port {port}")
Expand Down Expand Up @@ -1674,7 +1675,7 @@ def _docker_omc_start(self) -> Tuple[subprocess.Popen, DockerPopen, str]:
break
else:
logger.error(f"Docker did not start. Log-file says:\n{self.get_log()}")
raise OMCSessionException(f"Docker did not start (timeout={self._timeout} might be too short "
raise OMCSessionException(f"Docker did not start (timeout={self._timeout:.2f}s might be too short "
"especially if you did not docker pull the image before this command).")

docker_process = self._docker_process_get(docker_cid=docker_cid)
Expand Down Expand Up @@ -1854,7 +1855,7 @@ def _omc_port_get(self) -> str:
break
else:
logger.error(f"WSL based OMC server did not start. Log-file says:\n{self.get_log()}")
raise OMCSessionException(f"WSL based OMC Server did not start (timeout={self._timeout}, "
raise OMCSessionException(f"WSL based OMC Server did not start (timeout={self._timeout:2f}s, "
f"logfile={repr(self._omc_logfile)}).")

logger.info(f"WSL based OMC Server is up and running at ZMQ port {port} "
Expand Down
Loading