diff --git a/OMPython/ModelicaSystem.py b/OMPython/ModelicaSystem.py index 0eea5f15..47914b06 100644 --- a/OMPython/ModelicaSystem.py +++ b/OMPython/ModelicaSystem.py @@ -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 @@ -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, ) @@ -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, ) diff --git a/OMPython/OMCSession.py b/OMPython/OMCSession.py index 79f8d16b..70aa9f49 100644 --- a/OMPython/OMCSession.py +++ b/OMPython/OMCSession.py @@ -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, @@ -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 @@ -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. @@ -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: """ @@ -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() @@ -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} " @@ -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 @@ -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}") @@ -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) @@ -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} "