diff options
| author | 2020-02-29 15:33:54 -0800 | |
|---|---|---|
| committer | 2020-03-22 15:54:44 -0700 | |
| commit | 249d13e9d25b4ab4a1207c65aa9c0ee59e55b733 (patch) | |
| tree | 29504d80c75aa9fa22c7a2d30b23c7726911263d | |
| parent | HelpChannels: remove name attribute access for channels in logs (diff) | |
HelpChannels: fix unawaited coro warning
Explicitly close the callback if it's a coroutine.
| -rw-r--r-- | bot/cogs/help_channels.py | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/bot/cogs/help_channels.py b/bot/cogs/help_channels.py index 5dbc40b6a..d6031d7ff 100644 --- a/bot/cogs/help_channels.py +++ b/bot/cogs/help_channels.py @@ -1,4 +1,5 @@ import asyncio +import inspect import itertools import json import logging @@ -603,12 +604,18 @@ class HelpChannels(Scheduler, commands.Cog): async def _scheduled_task(self, data: TaskData) -> None: """Await the `data.callback` coroutine after waiting for `data.wait_time` seconds.""" - log.trace(f"Waiting {data.wait_time} seconds before awaiting callback.") - await asyncio.sleep(data.wait_time) - - # Use asyncio.shield to prevent callback from cancelling itself. - # The parent task (_scheduled_task) will still get cancelled. - await asyncio.shield(data.callback) + try: + log.trace(f"Waiting {data.wait_time} seconds before awaiting callback.") + await asyncio.sleep(data.wait_time) + + # Use asyncio.shield to prevent callback from cancelling itself. + # The parent task (_scheduled_task) will still get cancelled. + log.trace("Done waiting; now awaiting the callback.") + await asyncio.shield(data.callback) + finally: + if inspect.iscoroutine(data.callback): + log.trace("Explicitly closing coroutine.") + data.callback.close() def validate_config() -> None: |