From 344c2219ec4fff768a691cb02fcee2979fe49c53 Mon Sep 17 00:00:00 2001 From: luukas Date: Wed, 2 Jun 2021 21:30:12 +0300 Subject: [PATCH] Handle SIGTERM --- main.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/main.py b/main.py index 7a58d968..4489bc9e 100644 --- a/main.py +++ b/main.py @@ -4,6 +4,7 @@ import json import time import argparse import logging.config +import signal """ Our custom classes / pip packages """ from app.classes.shared.console import console @@ -128,6 +129,15 @@ if __name__ == '__main__': tasks_manager.start_main_kill_switch_watcher() Crafty = MainPrompt(tasks_manager) + + def sigterm_handler(signum, current_stack_frame): + print() # for newline + logger.info("Recieved SIGTERM, stopping Crafty") + console.info("Recieved SIGTERM, stopping Crafty") + Crafty.universal_exit() + + signal.signal(signal.SIGTERM, sigterm_handler) + if not args.daemon: try: Crafty.cmdloop()