From 4f24417417264b83b4a13f8ad5723a986ee15e56 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Fri, 18 Feb 2022 08:41:17 +0000 Subject: [PATCH] Handle trying to stop the bot when threads are running --- handler/app.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/handler/app.py b/handler/app.py index 717c1f0..44583ab 100755 --- a/handler/app.py +++ b/handler/app.py @@ -8,6 +8,7 @@ from klein import Klein # Other library imports from json import dumps, loads from json.decoder import JSONDecodeError +from signal import signal, SIGINT # Project imports from settings import settings @@ -18,6 +19,26 @@ from irc import bot from notify import Notify from markets import Markets +init_map = None + + +def handler(sig, frame): + cleanup() + + +def cleanup(): + if init_map: + try: + init_map["tx"].lc_es_checks.stop() + init_map["agora"].lc_dash.stop() + init_map["agora"].lc_cheat.stop() + except: # noqa + pass # noqa + reactor.stop() + + +signal(SIGINT, handler) # Handle Ctrl-C and run the cleanup routine + def convert(data): if isinstance(data, bytes): @@ -80,6 +101,8 @@ if __name__ == "__main__": # Schedule repeatedly refreshing the access token lc = LoopingCall(init_map["revolut"].get_new_token) lc.start(int(settings.Revolut.RefreshSec)) + # Set up the loops to put data in ES + init_map["tx"].setup_loops() # Run the WebApp init_map["webapp"].app.run("127.0.0.1", 8080)