From 67b0e46b4a467bf12292112dd04ba0e593538320 Mon Sep 17 00:00:00 2001 From: Jon Holba Date: Fri, 21 Jun 2024 15:08:35 +0200 Subject: [PATCH] Convert dict access of ForwardModel to get to avoid segfaults --- src/ert/ensemble_evaluator/evaluator.py | 2 +- src/ert/gui/model/snapshot.py | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/ert/ensemble_evaluator/evaluator.py b/src/ert/ensemble_evaluator/evaluator.py index 19c1e37a472..7783ba8b5c1 100644 --- a/src/ert/ensemble_evaluator/evaluator.py +++ b/src/ert/ensemble_evaluator/evaluator.py @@ -137,7 +137,7 @@ def _stopped_handler(self, events: List[CloudEvent]) -> None: with self._snapshot_mutex: max_memory_usage = -1 for job in self.ensemble.snapshot.get_all_forward_models().values(): - memory_usage = job[ids.MAX_MEMORY_USAGE] or "-1" + memory_usage = job.get(ids.MAX_MEMORY_USAGE) or "-1" max_memory_usage = max(int(memory_usage), max_memory_usage) logger.info( f"Ensemble ran with maximum memory usage for a single realization job: {max_memory_usage}" diff --git a/src/ert/gui/model/snapshot.py b/src/ert/gui/model/snapshot.py index 8fe54ab7d24..b4b91129bab 100644 --- a/src/ert/gui/model/snapshot.py +++ b/src/ert/gui/model/snapshot.py @@ -469,7 +469,7 @@ def _job_data(index: QModelIndex, node: ForwardModelStepNode, role: int): data_name = COLUMNS[NodeType.REAL][index.column()] if data_name in [ids.CURRENT_MEMORY_USAGE, ids.MAX_MEMORY_USAGE]: data = node.data - _bytes: Optional[str] = data[data_name] + _bytes: Optional[str] = data.get(data_name) if _bytes: return byte_with_unit(float(_bytes)) @@ -477,10 +477,12 @@ def _job_data(index: QModelIndex, node: ForwardModelStepNode, role: int): return "OPEN" if data_name in node.data else QVariant() if data_name in [DURATION]: - start_time = node.data[ids.START_TIME] + start_time = node.data.get(ids.START_TIME) if start_time is None: return QVariant() - delta = _estimate_duration(start_time, end_time=node.data[ids.END_TIME]) + delta = _estimate_duration( + start_time, end_time=node.data.get(ids.END_TIME) + ) # There is no method for truncating microseconds, so we remove them delta -= datetime.timedelta(microseconds=delta.microseconds) return str(delta) @@ -490,7 +492,7 @@ def _job_data(index: QModelIndex, node: ForwardModelStepNode, role: int): COLOR_RUNNING in real.data.forward_model_step_status_color_by_id.values() ): - return node.data[data_name] + return node.data.get(data_name) # if queue system status is WAIT, jobs should indicate WAIT if ( @@ -500,7 +502,7 @@ def _job_data(index: QModelIndex, node: ForwardModelStepNode, role: int): == COLOR_PENDING ): return str("Waiting") - return node.data[data_name] + return node.data.get(data_name) if role == FileRole: data_name = COLUMNS[NodeType.REAL][index.column()] @@ -517,12 +519,12 @@ def _job_data(index: QModelIndex, node: ForwardModelStepNode, role: int): data_name = COLUMNS[NodeType.REAL][index.column()] data = None if data_name == ids.ERROR: - data = node.data[ids.ERROR] + data = node.data.get(ids.ERROR) elif data_name == DURATION: - start_time = node.data[ids.START_TIME] + start_time = node.data.get(ids.START_TIME) if start_time is not None: delta = _estimate_duration( - start_time, end_time=node.data[ids.END_TIME] + start_time, end_time=node.data.get(ids.END_TIME) ) data = f"Start time: {str(start_time)}\nDuration: {str(delta)}" if data is not None: