aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel <[email protected]>2016-04-22 22:40:25 -0400
committerDaniel <[email protected]>2016-04-22 22:40:25 -0400
commit5a2b8e2ce6d4718fb987112d6854558025de2061 (patch)
tree98d6b82a37778d6f8ab20cca57a2b8ecf06bfe92
parentAdd optional redirect_uri parameter to utils.oauth_url (diff)
downloaddiscord.py-5a2b8e2ce6d4718fb987112d6854558025de2061.tar.xz
discord.py-5a2b8e2ce6d4718fb987112d6854558025de2061.zip
Properly close session if client failed to start
`keep_alive` was not defined until it was created in `received_message`, `ws` is `None` until its actually connected, which doesn't always happen. If an error happens before things start up properly, the client should now clean its objects up (fixes `unclosed client session` warning).
-rw-r--r--discord/client.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/discord/client.py b/discord/client.py
index 2d17c62b..8e5f1c04 100644
--- a/discord/client.py
+++ b/discord/client.py
@@ -118,6 +118,7 @@ class Client:
self.gateway = None
self.voice = None
self.session_id = None
+ self.keep_alive = None
self.sequence = 0
self.loop = asyncio.get_event_loop() if loop is None else loop
self._listeners = []
@@ -589,12 +590,13 @@ class Client:
yield from self.voice.disconnect()
self.voice = None
- if self.ws.open:
+ if self.ws is not None and self.ws.open:
yield from self.ws.close()
+ if self.keep_alive is not None:
+ self.keep_alive.cancel()
yield from self.session.close()
- self.keep_alive.cancel()
self._closed.set()
self._is_ready.clear()