aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar MarkKoz <[email protected]>2020-02-15 19:57:58 -0800
committerGravatar MarkKoz <[email protected]>2020-02-15 19:57:58 -0800
commit95fd3511f504adbe4ac806b4c706ff106466e4fb (patch)
treebac141f75737d2fcf644f9d24028f25730586c6e
parentMerge pull request #752 from python-discord/infr-edit-permanent-fix (diff)
Scheduler: fix #754 - only suppress CancelledError
-rw-r--r--bot/utils/scheduling.py13
1 files changed, 7 insertions, 6 deletions
diff --git a/bot/utils/scheduling.py b/bot/utils/scheduling.py
index ee6c0a8e6..8d4721d70 100644
--- a/bot/utils/scheduling.py
+++ b/bot/utils/scheduling.py
@@ -63,12 +63,13 @@ def create_task(loop: asyncio.AbstractEventLoop, coro_or_future: Union[Coroutine
"""Creates an asyncio.Task object from a coroutine or future object."""
task: asyncio.Task = asyncio.ensure_future(coro_or_future, loop=loop)
- # Silently ignore exceptions in a callback (handles the CancelledError nonsense)
- task.add_done_callback(_silent_exception)
+ # Silently ignore CancelledError in a callback
+ task.add_done_callback(_suppress_cancelled_error)
return task
-def _silent_exception(future: asyncio.Future) -> None:
- """Suppress future's exception."""
- with contextlib.suppress(Exception):
- future.exception()
+def _suppress_cancelled_error(future: asyncio.Future) -> None:
+ """Suppress future's CancelledError exception."""
+ if future.cancelled():
+ with contextlib.suppress(asyncio.CancelledError):
+ future.exception()