Improve server threads shutdown on SIGTERM

This commit is contained in:
allegroai
2019-12-29 09:04:07 +02:00
parent 87d2b6fa15
commit ed910d5f6a
6 changed files with 38 additions and 26 deletions

View File

@@ -1,3 +1,4 @@
import atexit
from argparse import ArgumentParser
from flask import Flask, request, Response
@@ -16,6 +17,7 @@ from service_repo.errors import PathParsingError
from timing_context import TimingContext
from updates import check_updates_thread
from utilities import json
from utilities.threads_manager import ThreadsManager
app = Flask(__name__, static_url_path="/static")
CORS(app, **config.get("apiserver.cors"))
@@ -41,6 +43,13 @@ check_updates_thread.start()
StatisticsReporter.start()
def graceful_shutdown():
ThreadsManager.terminating = True
atexit.register(graceful_shutdown)
@app.before_first_request
def before_app_first_request():
pass