Browse Source

Properly propagate loop. Fixes #420.

pull/314/merge
Rapptz 8 years ago
parent
commit
bed2e90e82
  1. 6
      discord/client.py
  2. 2
      discord/ext/commands/bot.py
  3. 4
      discord/http.py
  4. 9
      discord/state.py

6
discord/client.py

@ -519,8 +519,8 @@ class Client:
self.loop.run_until_complete(self.start(*args, **kwargs)) self.loop.run_until_complete(self.start(*args, **kwargs))
except KeyboardInterrupt: except KeyboardInterrupt:
self.loop.run_until_complete(self.logout()) self.loop.run_until_complete(self.logout())
pending = asyncio.Task.all_tasks() pending = asyncio.Task.all_tasks(loop=self.loop)
gathered = asyncio.gather(*pending) gathered = asyncio.gather(*pending, loop=self.loop)
try: try:
gathered.cancel() gathered.cancel()
self.loop.run_until_complete(gathered) self.loop.run_until_complete(gathered)
@ -1393,7 +1393,7 @@ class Client:
to_delete = ret[-100:] to_delete = ret[-100:]
yield from self.delete_messages(to_delete) yield from self.delete_messages(to_delete)
count = 0 count = 0
yield from asyncio.sleep(1) yield from asyncio.sleep(1, loop=self.loop)
if check(msg): if check(msg):
count += 1 count += 1

2
discord/ext/commands/bot.py

@ -311,7 +311,7 @@ class Bot(GroupMixin, discord.Client):
if delete_after is not None: if delete_after is not None:
@asyncio.coroutine @asyncio.coroutine
def delete(): def delete():
yield from asyncio.sleep(delete_after) yield from asyncio.sleep(delete_after, loop=self.loop)
yield from self.delete_message(msg) yield from self.delete_message(msg)
discord.compat.create_task(delete(), loop=self.loop) discord.compat.create_task(delete(), loop=self.loop)

4
discord/http.py

@ -120,12 +120,12 @@ class HTTPClient:
# sleep a bit # sleep a bit
retry_after = data['retry_after'] / 1000.0 retry_after = data['retry_after'] / 1000.0
log.info(fmt.format(retry_after, bucket)) log.info(fmt.format(retry_after, bucket))
yield from asyncio.sleep(retry_after) yield from asyncio.sleep(retry_after, loop=self.loop)
continue continue
# we've received a 502, unconditional retry # we've received a 502, unconditional retry
if r.status == 502 and tries <= 5: 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 continue
# the usual error cases # the usual error cases

9
discord/state.py

@ -170,7 +170,7 @@ class ConnectionState:
# this snippet of code is basically waiting 2 seconds # this snippet of code is basically waiting 2 seconds
# until the last GUILD_CREATE was sent # until the last GUILD_CREATE was sent
launch.set() launch.set()
yield from asyncio.sleep(2) yield from asyncio.sleep(2, loop=self.loop)
servers = self._ready_state.servers servers = self._ready_state.servers
@ -187,7 +187,7 @@ class ConnectionState:
# wait for the chunks # wait for the chunks
if chunks: if chunks:
try: try:
yield from asyncio.wait(chunks, timeout=len(chunks)) yield from asyncio.wait(chunks, timeout=len(chunks), loop=self.loop)
except asyncio.TimeoutError: except asyncio.TimeoutError:
log.info('Somehow timed out waiting for chunks.') log.info('Somehow timed out waiting for chunks.')
@ -489,7 +489,10 @@ class ConnectionState:
yield from self.chunker(server) yield from self.chunker(server)
chunks = list(self.chunks_needed(server)) chunks = list(self.chunks_needed(server))
if chunks: 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: if unavailable == False:
self.dispatch('server_available', server) self.dispatch('server_available', server)

Loading…
Cancel
Save