aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2019-05-13 22:07:43 -0400
committerRapptz <[email protected]>2019-05-13 22:10:38 -0400
commit6bc9d7c01a849a04fdbc15f4b10eacf6d7356b19 (patch)
treece1fcd66e28e6d7a32adaf183e3bb07c32ba9498
parent[tasks] Log exception when something failed to logging. (diff)
downloaddiscord.py-6bc9d7c01a849a04fdbc15f4b10eacf6d7356b19.tar.xz
discord.py-6bc9d7c01a849a04fdbc15f4b10eacf6d7356b19.zip
[tasks] Add indicator for internal task failure
Fixes #2151
-rw-r--r--discord/ext/tasks/__init__.py14
1 files changed, 12 insertions, 2 deletions
diff --git a/discord/ext/tasks/__init__.py b/discord/ext/tasks/__init__.py
index 649fbd48..54308644 100644
--- a/discord/ext/tasks/__init__.py
+++ b/discord/ext/tasks/__init__.py
@@ -41,6 +41,7 @@ class Loop:
self._before_loop = None
self._after_loop = None
self._is_being_cancelled = False
+ self._has_failed = False
self._stop_next_iteration = False
if self.count is not None and self.count <= 0:
@@ -89,7 +90,8 @@ class Loop:
except asyncio.CancelledError:
self._is_being_cancelled = True
raise
- except Exception as e:
+ except Exception:
+ self._has_failed = True
log.exception('Internal background task failed.')
raise
finally:
@@ -97,6 +99,7 @@ class Loop:
self._is_being_cancelled = False
self._current_loop = 0
self._stop_next_iteration = False
+ self._has_failed = False
def __get__(self, obj, objtype):
if obj is None:
@@ -155,7 +158,7 @@ class Loop:
before stopping via :meth:`clear_exception_types` or
use :meth:`cancel` instead.
- .. versionadded:: 1.2
+ .. versionadded:: 1.2.0
"""
if self._task and not self._task.done():
self._stop_next_iteration = True
@@ -254,6 +257,13 @@ class Loop:
""":class:`bool`: Whether the task is being cancelled."""
return self._is_being_cancelled
+ def failed(self):
+ """:class:`bool`: Whether the internal task has failed.
+
+ .. versionadded:: 1.2.0
+ """
+ return self._has_failed
+
def before_loop(self, coro):
"""A decorator that registers a coroutine to be called before the loop starts running.