Improve stop behavior in SIGTERM cases (docker).

This commit is contained in:
Matthias 2023-02-13 18:25:15 +01:00
parent aafaff877b
commit 69d5459460

View File

@ -1,4 +1,5 @@
import logging import logging
import signal
from typing import Any, Dict from typing import Any, Dict
@ -12,15 +13,20 @@ def start_trading(args: Dict[str, Any]) -> int:
# Import here to avoid loading worker module when it's not used # Import here to avoid loading worker module when it's not used
from freqtrade.worker import Worker from freqtrade.worker import Worker
def term_handler(signum, frame):
# Raise KeyboardInterrupt - so we can handle it in the same way as Ctrl-C
raise KeyboardInterrupt()
# Create and run worker # Create and run worker
worker = None worker = None
try: try:
signal.signal(signal.SIGTERM, term_handler)
worker = Worker(args) worker = Worker(args)
worker.run() worker.run()
except Exception as e: except Exception as e:
logger.error(str(e)) logger.error(str(e))
logger.exception("Fatal exception!") logger.exception("Fatal exception!")
except KeyboardInterrupt: except (KeyboardInterrupt):
logger.info('SIGINT received, aborting ...') logger.info('SIGINT received, aborting ...')
finally: finally:
if worker: if worker: