aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2019-04-08 23:36:31 -0400
committerRapptz <[email protected]>2019-04-09 00:14:42 -0400
commitdcdcf1adacf7d8a3c0632fa4563d641745dfcf1b (patch)
tree4092f48a9fc2f1af7e4bc4199cea7abeabe1c008
parentUse is_connected() instead of _connected in checks (diff)
downloaddiscord.py-dcdcf1adacf7d8a3c0632fa4563d641745dfcf1b.tar.xz
discord.py-dcdcf1adacf7d8a3c0632fa4563d641745dfcf1b.zip
Stop the event loop if it's running during cleanup.
Also handle the coroutine directly instead of using run_until_complete
-rw-r--r--discord/client.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/discord/client.py b/discord/client.py
index a72c1582..2ce85d27 100644
--- a/discord/client.py
+++ b/discord/client.py
@@ -501,6 +501,10 @@ class Client:
if loop.is_closed():
return # we're already cleaning up
+ # Stop the event loop if it's running
+ if loop.is_running():
+ loop.stop()
+
task = asyncio.ensure_future(self.close(), loop=loop)
def stop_loop(fut):
@@ -553,8 +557,11 @@ class Client:
loop.add_signal_handler(signal.SIGINT, self._do_cleanup)
loop.add_signal_handler(signal.SIGTERM, self._do_cleanup)
+ future = asyncio.ensure_future(self.start(*args, **kwargs), loop=loop)
+ future.add_done_callback(lambda f: loop.stop())
+
try:
- loop.run_until_complete(self.start(*args, **kwargs))
+ loop.run_forever()
except KeyboardInterrupt:
log.info('Received signal to terminate bot and event loop.')
finally: