diff options
| -rw-r--r-- | bot/utils/scheduling.py | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/bot/utils/scheduling.py b/bot/utils/scheduling.py index 00fca4169..6f498348d 100644 --- a/bot/utils/scheduling.py +++ b/bot/utils/scheduling.py @@ -39,17 +39,17 @@ class Scheduler: If `ignore_missing` is True, a warning will not be sent if a task isn't found. """ self._log.trace(f"Cancelling task #{task_id}...") - task = self._scheduled_tasks.get(task_id) - if not task: + try: + task = self._scheduled_tasks.pop(task_id) + except KeyError: if not ignore_missing: self._log.warning(f"Failed to unschedule {task_id} (no task found).") - return - - del self._scheduled_tasks[task_id] - task.cancel() + else: + del self._scheduled_tasks[task_id] + task.cancel() - self._log.debug(f"Unscheduled task #{task_id} {id(task)}.") + self._log.debug(f"Unscheduled task #{task_id} {id(task)}.") def cancel_all(self) -> None: """Unschedule all known tasks.""" |