aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2017-05-20 11:58:29 -0400
committerRapptz <[email protected]>2017-05-20 11:58:29 -0400
commit1e1b02c630eba5c339ccd7f00f2a9925efb6abcb (patch)
tree8232d08bad271667bfe765c648a214ac62bfe75a
parentWarnings are yellow. (diff)
downloaddiscord.py-1e1b02c630eba5c339ccd7f00f2a9925efb6abcb.tar.xz
discord.py-1e1b02c630eba5c339ccd7f00f2a9925efb6abcb.zip
Check if we're closing the event loop before using it.
Should fix #545.
-rw-r--r--discord/client.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/discord/client.py b/discord/client.py
index 021be0a8..ea216dd1 100644
--- a/discord/client.py
+++ b/discord/client.py
@@ -454,6 +454,9 @@ class Client:
def _do_cleanup(self):
+ if self.loop.is_closed() or not self.loop.is_running():
+ return # we're already cleaning up
+
self.loop.run_until_complete(self.close())
pending = asyncio.Task.all_tasks(loop=self.loop)
if pending:
@@ -469,6 +472,8 @@ class Client:
except:
pass
+ self.loop.close()
+
def run(self, *args, **kwargs):
"""A blocking call that abstracts away the `event loop`_
initialisation from you.
@@ -503,7 +508,6 @@ class Client:
pass
finally:
self._do_cleanup()
- self.loop.close()
# properties