aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar MarkKoz <[email protected]>2020-06-23 23:52:50 -0700
committerGravatar MarkKoz <[email protected]>2020-06-23 23:52:50 -0700
commit58d20203870f293de9410db4bf0e602696d04c2c (patch)
tree79e0062a67fca5456536498d5f4cdf0bcd8d740e
parentUpdate InfractionScheduler's scheduler to the new API (diff)
Scheduler: close coroutine if task ID already exists
This prevents unawaited coroutine warnings.
-rw-r--r--bot/utils/scheduling.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/bot/utils/scheduling.py b/bot/utils/scheduling.py
index f5308059a..4e99db76c 100644
--- a/bot/utils/scheduling.py
+++ b/bot/utils/scheduling.py
@@ -20,11 +20,17 @@ class Scheduler:
return task_id in self._scheduled_tasks
def schedule(self, task_id: t.Hashable, coroutine: t.Coroutine) -> None:
- """Schedule the execution of a coroutine."""
+ """
+ Schedule the execution of a coroutine.
+
+ If a task with `task_id` already exists, close `coroutine` instead of scheduling it.
+ This prevents unawaited coroutine warnings.
+ """
self._log.trace(f"Scheduling task #{task_id}...")
if task_id in self._scheduled_tasks:
self._log.debug(f"Did not schedule task #{task_id}; task was already scheduled.")
+ coroutine.close()
return
task = asyncio.create_task(coroutine, name=f"{self.name}_{task_id}")