From 870002334901d414cfbf934ecec4743181a7b9ca Mon Sep 17 00:00:00 2001 From: s3lph Date: Mon, 3 Feb 2020 23:39:51 +0100 Subject: [PATCH] Fix SIGINT termination issues --- matemat/__main__.py | 14 +++++++++----- matemat/webserver/cron.py | 4 ++++ matemat/webserver/pagelets/__init__.py | 1 - 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/matemat/__main__.py b/matemat/__main__.py index 8a773f7..5da5ea8 100644 --- a/matemat/__main__.py +++ b/matemat/__main__.py @@ -1,11 +1,11 @@ - from typing import Any, Dict, Iterable, Union -from bottle import route, static_file, run import sys import os.path +import bottle from matemat.db import MatematDatabase +from matemat.webserver import cron from matemat.webserver.logger import Logger from matemat.webserver.config import get_config, parse_config_file from matemat.webserver.template import init as template_init @@ -59,11 +59,11 @@ def _init(config: Dict[str, Any]): template_init(config) -@route('/static/') +@bottle.route('/static/') def serve_static_files(filename: str): config = get_config() staticroot = os.path.abspath(config['staticroot']) - return static_file(filename, root=staticroot) + return bottle.static_file(filename, root=staticroot) def main(): @@ -80,8 +80,12 @@ def main(): host: str = config['listen'] port: int = int(str(config['port'])) + # noinspection PyUnresolvedReferences + from matemat.webserver.pagelets.receipt_smtp_cron import receipt_smtp_cron # Start the web server - run(host=host, port=port, debug=True) + bottle.run(host=host, port=port) + # Stop cron + cron.shutdown() if __name__ == '__main__': diff --git a/matemat/webserver/cron.py b/matemat/webserver/cron.py index ce78acf..fa9051b 100644 --- a/matemat/webserver/cron.py +++ b/matemat/webserver/cron.py @@ -8,6 +8,10 @@ from matemat.webserver import Logger _CRON_STATIC_EVENT: Event = Event() +def shutdown(*_args, **_kwargs): + _CRON_STATIC_EVENT.set() + + class _GlobalEventTimer(Thread): """ A timer similar to threading.Timer, except that waits on an externally supplied threading.Event instance, diff --git a/matemat/webserver/pagelets/__init__.py b/matemat/webserver/pagelets/__init__.py index bc4f3c4..629cd5f 100644 --- a/matemat/webserver/pagelets/__init__.py +++ b/matemat/webserver/pagelets/__init__.py @@ -15,4 +15,3 @@ from .moduser import moduser from .modproduct import modproduct from .userbootstrap import userbootstrap from .statistics import statistics -from .receipt_smtp_cron import receipt_smtp_cron