From bed2e90e825f9cf90fc1ecbae3f49472de05ad3c Mon Sep 17 00:00:00 2001 From: Rapptz Date: Wed, 21 Dec 2016 00:01:00 -0500 Subject: [PATCH] Properly propagate loop. Fixes #420. --- discord/client.py | 6 +++--- discord/ext/commands/bot.py | 2 +- discord/http.py | 4 ++-- discord/state.py | 9 ++++++--- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/discord/client.py b/discord/client.py index 8cfe48ef7..f8cd4c324 100644 --- a/discord/client.py +++ b/discord/client.py @@ -519,8 +519,8 @@ class Client: self.loop.run_until_complete(self.start(*args, **kwargs)) except KeyboardInterrupt: self.loop.run_until_complete(self.logout()) - pending = asyncio.Task.all_tasks() - gathered = asyncio.gather(*pending) + pending = asyncio.Task.all_tasks(loop=self.loop) + gathered = asyncio.gather(*pending, loop=self.loop) try: gathered.cancel() self.loop.run_until_complete(gathered) @@ -1393,7 +1393,7 @@ class Client: to_delete = ret[-100:] yield from self.delete_messages(to_delete) count = 0 - yield from asyncio.sleep(1) + yield from asyncio.sleep(1, loop=self.loop) if check(msg): count += 1 diff --git a/discord/ext/commands/bot.py b/discord/ext/commands/bot.py index 349e5d0d9..d23eeb492 100644 --- a/discord/ext/commands/bot.py +++ b/discord/ext/commands/bot.py @@ -311,7 +311,7 @@ class Bot(GroupMixin, discord.Client): if delete_after is not None: @asyncio.coroutine def delete(): - yield from asyncio.sleep(delete_after) + yield from asyncio.sleep(delete_after, loop=self.loop) yield from self.delete_message(msg) discord.compat.create_task(delete(), loop=self.loop) diff --git a/discord/http.py b/discord/http.py index fdeaa4783..38b7ff8e1 100644 --- a/discord/http.py +++ b/discord/http.py @@ -120,12 +120,12 @@ class HTTPClient: # sleep a bit retry_after = data['retry_after'] / 1000.0 log.info(fmt.format(retry_after, bucket)) - yield from asyncio.sleep(retry_after) + yield from asyncio.sleep(retry_after, loop=self.loop) continue # we've received a 502, unconditional retry if r.status == 502 and tries <= 5: - yield from asyncio.sleep(1 + tries * 2) + yield from asyncio.sleep(1 + tries * 2, loop=self.loop) continue # the usual error cases diff --git a/discord/state.py b/discord/state.py index aed5a7463..48a75a473 100644 --- a/discord/state.py +++ b/discord/state.py @@ -170,7 +170,7 @@ class ConnectionState: # this snippet of code is basically waiting 2 seconds # until the last GUILD_CREATE was sent launch.set() - yield from asyncio.sleep(2) + yield from asyncio.sleep(2, loop=self.loop) servers = self._ready_state.servers @@ -187,7 +187,7 @@ class ConnectionState: # wait for the chunks if chunks: try: - yield from asyncio.wait(chunks, timeout=len(chunks)) + yield from asyncio.wait(chunks, timeout=len(chunks), loop=self.loop) except asyncio.TimeoutError: log.info('Somehow timed out waiting for chunks.') @@ -489,7 +489,10 @@ class ConnectionState: yield from self.chunker(server) chunks = list(self.chunks_needed(server)) if chunks: - yield from asyncio.wait(chunks) + try: + yield from asyncio.wait(chunks, timeout=len(chunks), loop=self.loop) + except asyncio.TimeoutError: + log.info('Somehow timed out waiting for chunks.') if unavailable == False: self.dispatch('server_available', server)