diff options
| author | 2020-07-06 10:09:03 -0700 | |
|---|---|---|
| committer | 2020-07-06 10:11:46 -0700 | |
| commit | 14cfd1e9dd4d149fb554b84969fed27f85ad5361 (patch) | |
| tree | 60dbe01af17d9e9c03410c46509606b443edf714 | |
| parent | Scheduler: more verbose logging in _await_later (diff) | |
Scheduler: assert the coroutine hasn't been awaited yet
It'd fail to schedule the coroutine otherwise anyway. There is also the
potential to close the coroutine, which may be unexpected to see for a
coroutine that was already running (despite being documented).
| -rw-r--r-- | bot/utils/scheduling.py | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/bot/utils/scheduling.py b/bot/utils/scheduling.py index 9fc519393..fddb0c2fe 100644 --- a/bot/utils/scheduling.py +++ b/bot/utils/scheduling.py @@ -43,6 +43,9 @@ class Scheduler: """ self._log.trace(f"Scheduling task #{task_id}...") + msg = f"Cannot schedule an already started coroutine for #{task_id}" + assert inspect.getcoroutinestate(coroutine) == "CORO_CREATED", msg + if task_id in self._scheduled_tasks: self._log.debug(f"Did not schedule task #{task_id}; task was already scheduled.") coroutine.close() |