From ea9b757f5358339d708cedeafbfecd7a83fa4ae8 Mon Sep 17 00:00:00 2001 From: larsevj Date: Mon, 13 Jan 2025 18:46:55 +0100 Subject: [PATCH] Use get_nowait in event queues --- src/ert/ensemble_evaluator/evaluator.py | 5 +++-- src/ert/gui/simulation/queue_emitter.py | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ert/ensemble_evaluator/evaluator.py b/src/ert/ensemble_evaluator/evaluator.py index 3696660524f..169f74603db 100644 --- a/src/ert/ensemble_evaluator/evaluator.py +++ b/src/ert/ensemble_evaluator/evaluator.py @@ -133,11 +133,12 @@ def set_event_handler(event_types: set[type[Event]], func: Any) -> None: ): self._complete_batch.clear() try: - event = await asyncio.wait_for(self._events.get(), timeout=0.1) + event = self._events.get_nowait() function = event_handler[type(event)] batch.append((function, event)) self._events.task_done() - except TimeoutError: + except asyncio.QueueEmpty: + await asyncio.sleep(0.1) continue self._complete_batch.set() await self._batch_processing_queue.put(batch) diff --git a/src/ert/gui/simulation/queue_emitter.py b/src/ert/gui/simulation/queue_emitter.py index dd07a5ff2fd..3f8b6e6bb71 100644 --- a/src/ert/gui/simulation/queue_emitter.py +++ b/src/ert/gui/simulation/queue_emitter.py @@ -36,7 +36,7 @@ def consume_and_emit(self) -> None: while True: event = None with suppress(Empty): - event = self._event_queue.get(timeout=1.0) + event = self._event_queue.get_nowait() if self._stopped: logger.debug("stopped") break