Handle trying to stop the bot when threads are running

This commit is contained in:
Mark Veidemanis 2022-02-18 08:41:17 +00:00
parent 62d3f1a953
commit 4f24417417
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
1 changed files with 23 additions and 0 deletions

View File

@ -8,6 +8,7 @@ from klein import Klein
# Other library imports # Other library imports
from json import dumps, loads from json import dumps, loads
from json.decoder import JSONDecodeError from json.decoder import JSONDecodeError
from signal import signal, SIGINT
# Project imports # Project imports
from settings import settings from settings import settings
@ -18,6 +19,26 @@ from irc import bot
from notify import Notify from notify import Notify
from markets import Markets 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): def convert(data):
if isinstance(data, bytes): if isinstance(data, bytes):
@ -80,6 +101,8 @@ if __name__ == "__main__":
# Schedule repeatedly refreshing the access token # Schedule repeatedly refreshing the access token
lc = LoopingCall(init_map["revolut"].get_new_token) lc = LoopingCall(init_map["revolut"].get_new_token)
lc.start(int(settings.Revolut.RefreshSec)) lc.start(int(settings.Revolut.RefreshSec))
# Set up the loops to put data in ES
init_map["tx"].setup_loops()
# Run the WebApp # Run the WebApp
init_map["webapp"].app.run("127.0.0.1", 8080) init_map["webapp"].app.run("127.0.0.1", 8080)