aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve C <[email protected]>2020-05-09 21:37:09 -0400
committerRapptz <[email protected]>2020-05-10 17:00:23 -0400
commit4b3a7fbe165e9bd28af4677d143f27cf2f75179d (patch)
tree25362c08596c8ccf00b63d3a0dea13a242d5a1f4
parentAdd support server as contact link in issue templates (diff)
downloaddiscord.py-4b3a7fbe165e9bd28af4677d143f27cf2f75179d.tar.xz
discord.py-4b3a7fbe165e9bd28af4677d143f27cf2f75179d.zip
[tasks] Allow Loop.cancel in Loop.before_loop
Task cancel raises on the next awaited coro, so I've added this 0-sleep "hack" I'm internally debating if leaving the comment there, but I'm sure it would confuse the uninformed of this trick.
-rw-r--r--discord/ext/tasks/__init__.py1
1 files changed, 1 insertions, 0 deletions
diff --git a/discord/ext/tasks/__init__.py b/discord/ext/tasks/__init__.py
index 36cfe810..833fc65a 100644
--- a/discord/ext/tasks/__init__.py
+++ b/discord/ext/tasks/__init__.py
@@ -68,6 +68,7 @@ class Loop:
sleep_until = discord.utils.sleep_until
self._next_iteration = datetime.datetime.now(datetime.timezone.utc)
try:
+ await asyncio.sleep(0) # allows canceling in before_loop
while True:
self._last_iteration = self._next_iteration
self._next_iteration = self._get_next_sleep_time()