From bb49ec12c34aa247c5a972695a318324fffa15ca Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Thu, 25 Nov 2021 21:56:44 +0100 Subject: [PATCH 1/1] Fix shutdown on error --- src/mtxbot.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/mtxbot.py b/src/mtxbot.py index 722c8db..573a5f2 100755 --- a/src/mtxbot.py +++ b/src/mtxbot.py @@ -36,6 +36,9 @@ async def main(): done, pending = await asyncio.wait( presence_tasks, return_when = asyncio.FIRST_EXCEPTION ) + for task in presence_tasks: + task.stop() + for task in done: try: task.result() @@ -43,6 +46,7 @@ async def main(): logging.error( "Error running task: %s" % str(e) ) finally: + logging.info("Closing client...") await client.close() logging.basicConfig(format='[%(asctime)s] %(levelname)s: %(message)s', @@ -51,6 +55,7 @@ logging.basicConfig(format='[%(asctime)s] %(levelname)s: %(message)s', mainPid = os.getpid() signal.signal(signal.SIGINT, handleInterrupt) +signal.signal(signal.SIGTERM, handleInterrupt) stop = False -- 2.39.5