aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar MarkKoz <[email protected]>2020-06-19 23:02:24 -0700
committerGravatar MarkKoz <[email protected]>2020-06-19 23:02:24 -0700
commitc81d3bdd1769a02ba02af18e52150629e655e3c9 (patch)
treea27a1fa6338f80d7354a9718df8eed055c234a27
parentScheduler: add support for in operator (diff)
Scheduler: use pop instead of get when cancelling
-rw-r--r--bot/utils/scheduling.py14
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."""