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 0ecc034
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 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
4 changes: 2 additions & 2 deletions src/ert/gui/simulation/run_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ def run() -> None:
restart=restart,
)

simulation_thread = ErtThread(
self.simulation_thread = ErtThread(
name="ert_gui_simulation_thread", target=run, daemon=True
)

Expand All @@ -381,7 +381,7 @@ def run() -> None:
self._ticker.start(self._RUN_TIME_POLL_RATE)

self._worker_thread.start()
simulation_thread.start()
self.simulation_thread.start()
self._notifier.set_is_simulation_running(True)

def killJobs(self) -> QMessageBox.StandardButton:
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 0ecc034

Please sign in to comment.