aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bot/cogs/help_channels.py4
-rw-r--r--bot/utils/scheduling.py9
2 files changed, 9 insertions, 4 deletions
diff --git a/bot/cogs/help_channels.py b/bot/cogs/help_channels.py
index 4c83e0722..01bcc28f7 100644
--- a/bot/cogs/help_channels.py
+++ b/bot/cogs/help_channels.py
@@ -119,9 +119,7 @@ class HelpChannels(Scheduler, commands.Cog):
for task in self.queue_tasks:
task.cancel()
- log.trace("Cog unload: cancelling the scheduled tasks")
- for task in self.scheduled_tasks.values():
- task.cancel()
+ self.cancel_all()
def create_channel_queue(self) -> asyncio.Queue:
"""
diff --git a/bot/utils/scheduling.py b/bot/utils/scheduling.py
index 5760ec2d4..e9a9e6c2d 100644
--- a/bot/utils/scheduling.py
+++ b/bot/utils/scheduling.py
@@ -60,11 +60,18 @@ class Scheduler(metaclass=CogABCMeta):
log.warning(f"{self.cog_name}: failed to unschedule {task_id} (no task found).")
return
- task.cancel()
del self._scheduled_tasks[task_id]
+ task.cancel()
log.debug(f"{self.cog_name}: unscheduled task #{task_id} {id(task)}.")
+ def cancel_all(self) -> None:
+ """Unschedule all known tasks."""
+ log.debug(f"{self.cog_name}: unscheduling all tasks")
+
+ for task_id in self._scheduled_tasks:
+ self.cancel_task(task_id)
+
def _task_done_callback(self, task_id: t.Hashable, done_task: asyncio.Task) -> None:
"""
Delete the task and raise its exception if one exists.