Skip to content

Commit

Permalink
Make sure event loop is running before running coroutines in executor
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-eq committed Jan 6, 2025
1 parent 719a81e commit 5934c72
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/ert/ensemble_evaluator/evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
14 changes: 8 additions & 6 deletions src/ert/run_models/base_run_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 5934c72

Please sign in to comment.