diff options
| author | 2020-02-25 20:15:58 -0800 | |
|---|---|---|
| committer | 2020-02-25 20:15:58 -0800 | |
| commit | df87aba432db50eb480ba8b2f42b1a64147909d9 (patch) | |
| tree | 7a3f46e8116209febf2415d7978a2363511eea76 | |
| parent | Merge remote-tracking branch 'origin/master' into bug/backend/b754/scheduler-... (diff) | |
Moderation: use asyncio.shield to prevent self-cancellation
The shield exists to be used for exactly this purpose so its a better
fit than create_task.
| -rw-r--r-- | bot/cogs/moderation/scheduler.py | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/bot/cogs/moderation/scheduler.py b/bot/cogs/moderation/scheduler.py index 162159af8..93afd9f9f 100644 --- a/bot/cogs/moderation/scheduler.py +++ b/bot/cogs/moderation/scheduler.py @@ -1,3 +1,4 @@ +import asyncio import logging import textwrap import typing as t @@ -427,6 +428,6 @@ class InfractionScheduler(Scheduler): expiry = dateutil.parser.isoparse(infraction["expires_at"]).replace(tzinfo=None) await time.wait_until(expiry) - # Because deactivate_infraction() explicitly cancels this scheduled task, it runs in - # a separate task to avoid prematurely cancelling itself. - self.bot.loop.create_task(self.deactivate_infraction(infraction)) + # Because deactivate_infraction() explicitly cancels this scheduled task, it is shielded + # to avoid prematurely cancelling itself. + await asyncio.shield(self.deactivate_infraction(infraction)) |