]> git.treefish.org Git - mtxbot.git/commitdiff
Fix shutdown on error
authorAlexander Schmidt <alex@treefish.org>
Thu, 25 Nov 2021 20:56:44 +0000 (21:56 +0100)
committerAlexander Schmidt <alex@treefish.org>
Thu, 25 Nov 2021 20:56:44 +0000 (21:56 +0100)
src/mtxbot.py

index 722c8dbb40097d514e70f61ce4da5147b8e12d95..573a5f22310cd2a07c82c7847a95797df7b22d37 100755 (executable)
@@ -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