From 6b7db007fc7623555d78f076b0ff1dcee01a7bb3 Mon Sep 17 00:00:00 2001 From: thegamecracks <61257169+thegamecracks@users.noreply.github.com> Date: Mon, 17 Jun 2024 21:29:17 -0400 Subject: [PATCH] feat: suppress CancelledError from async runner --- sardine_core/scheduler/async_runner.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sardine_core/scheduler/async_runner.py b/sardine_core/scheduler/async_runner.py index f176b990..4daef263 100644 --- a/sardine_core/scheduler/async_runner.py +++ b/sardine_core/scheduler/async_runner.py @@ -436,7 +436,7 @@ def start(self): return self._task = asyncio.create_task(self._runner()) - self._task.add_done_callback(asyncio.Task.result) + self._task.add_done_callback(self._on_task_done) def is_running(self) -> bool: """Returns True if the runner is running.""" @@ -867,3 +867,9 @@ def _skip_iteration(self) -> None: def _jump_start_iteration(self) -> None: self._jump_start = True self._skip_iteration() + + def _on_task_done(self, task: asyncio.Task) -> None: + if task.cancelled(): + return # Suppress CancelledError + + task.result() # Raise any exception if present