From 13d95dba9c1d361567772b3d5a00b3d6c891a3b7 Mon Sep 17 00:00:00 2001 From: vfdev Date: Mon, 9 Dec 2024 13:41:35 +0100 Subject: [PATCH] Apply suggestions from code review --- ignite/engine/engine.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ignite/engine/engine.py b/ignite/engine/engine.py index dd3ae3db863..c476aa6789d 100644 --- a/ignite/engine/engine.py +++ b/ignite/engine/engine.py @@ -998,7 +998,10 @@ def _internal_run_as_gen(self) -> Generator[Any, None, State]: # update time wrt handlers self.state.times[Events.EPOCH_COMPLETED.name] = epoch_time_taken - self.should_terminate_single_epoch = False + if self.should_terminate_single_epoch: + # We skip raising _EngineTerminateSingleEpochException exception on Events.EPOCH_COMPLETED + # as epoch is already completed and nothing to terminate + self.should_terminate_single_epoch = False yield from self._maybe_terminate_or_interrupt() hours, mins, secs = _to_hours_mins_secs(epoch_time_taken) @@ -1192,7 +1195,10 @@ def _internal_run_legacy(self) -> State: # update time wrt handlers self.state.times[Events.EPOCH_COMPLETED.name] = epoch_time_taken - self.should_terminate_single_epoch = False + if self.should_terminate_single_epoch: + # We skip raising _EngineTerminateSingleEpochException exception on Events.EPOCH_COMPLETED + # as epoch is already completed and nothing to terminate + self.should_terminate_single_epoch = False self._maybe_terminate_legacy() hours, mins, secs = _to_hours_mins_secs(epoch_time_taken)