aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2019-04-07 16:10:44 -0400
committerRapptz <[email protected]>2019-04-07 16:10:44 -0400
commit84c1eac62a775a37b03bd0971b221b0c50724630 (patch)
treef518d50f3cfe7d319ada60c6e116b63a06c7129e
parentForgot to escape backticks. (diff)
downloaddiscord.py-84c1eac62a775a37b03bd0971b221b0c50724630.tar.xz
discord.py-84c1eac62a775a37b03bd0971b221b0c50724630.zip
Don't raise an exception during the signal handlers.
-rw-r--r--discord/client.py17
1 files changed, 7 insertions, 10 deletions
diff --git a/discord/client.py b/discord/client.py
index 0829f154..2608fa6e 100644
--- a/discord/client.py
+++ b/discord/client.py
@@ -55,12 +55,6 @@ from .appinfo import AppInfo
log = logging.getLogger(__name__)
-class _ProperCleanup(Exception):
- pass
-
-def _raise_proper_cleanup():
- raise _ProperCleanup
-
def _cancel_tasks(loop, tasks):
if not tasks:
return
@@ -503,6 +497,8 @@ class Client:
def _do_cleanup(self):
log.info('Cleaning up event loop.')
loop = self.loop
+ if loop.is_closed():
+ return # we're already cleaning up
task = asyncio.ensure_future(self.close(), loop=loop)
@@ -553,15 +549,16 @@ class Client:
is_windows = sys.platform == 'win32'
loop = self.loop
if not is_windows:
- loop.add_signal_handler(signal.SIGINT, _raise_proper_cleanup)
- loop.add_signal_handler(signal.SIGTERM, _raise_proper_cleanup)
+ loop.add_signal_handler(signal.SIGINT, self._do_cleanup)
+ loop.add_signal_handler(signal.SIGTERM, self._do_cleanup)
try:
loop.run_until_complete(self.start(*args, **kwargs))
- except (_ProperCleanup, KeyboardInterrupt):
+ except KeyboardInterrupt:
log.info('Received signal to terminate bot and event loop.')
finally:
- self._do_cleanup()
+ if is_windows:
+ self._do_cleanup()
# properties