diff --git a/src/ert/ensemble_evaluator/evaluator.py b/src/ert/ensemble_evaluator/evaluator.py index 3696660524f..5a5a093bd60 100644 --- a/src/ert/ensemble_evaluator/evaluator.py +++ b/src/ert/ensemble_evaluator/evaluator.py @@ -334,7 +334,8 @@ def _signal_cancel(self) -> None: if self._ensemble.cancellable: logger.debug("Cancelling current ensemble") assert self._loop is not None - self._loop.run_in_executor(None, self._ensemble.cancel) + if self._loop.is_running(): + self._loop.run_in_executor(None, self._ensemble.cancel) else: logger.debug("Stopping current ensemble") self.stop() diff --git a/src/ert/run_models/base_run_model.py b/src/ert/run_models/base_run_model.py index a9f00f059f6..a24f68a2244 100644 --- a/src/ert/run_models/base_run_model.py +++ b/src/ert/run_models/base_run_model.py @@ -503,12 +503,14 @@ async def run_monitor( EESnapshotUpdate, }: event = cast(EESnapshot | EESnapshotUpdate, event) - await asyncio.get_running_loop().run_in_executor( - None, - self.send_snapshot_event, - event, - iteration, - ) + if asyncio.get_running_loop().is_running(): + await asyncio.get_running_loop().run_in_executor( + None, + self.send_snapshot_event, + event, + iteration, + ) + if event.snapshot.get(STATUS) in { ENSEMBLE_STATE_STOPPED, ENSEMBLE_STATE_FAILED,