web_server: Move shutdown handling to main

This will keep web server de-coupled with service that want to shutdown on exit.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2019-02-21 11:47:46 -08:00 committed by James Valleroy
parent adb08df512
commit 94255806cf
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
2 changed files with 9 additions and 9 deletions

View File

@ -126,6 +126,11 @@ def adapt_config(arguments):
setattr(cfg, argument_name, argument_value)
def on_web_server_stop():
"""Stop all other threads since web server is trying to exit."""
setup.stop()
def main():
"""Intialize and start the application"""
arguments = parse_arguments()
@ -173,7 +178,7 @@ def main():
setup.run_setup_in_background()
web_server.init()
web_server.run()
web_server.run(on_web_server_stop)
if __name__ == '__main__':

View File

@ -23,7 +23,7 @@ import os
import cherrypy
from . import cfg, log, module_loader, setup, web_framework
from . import cfg, log, module_loader, web_framework
logger = logging.getLogger(__name__)
@ -89,13 +89,8 @@ def init():
cherrypy.engine.signal_handler.subscribe()
def on_server_stop():
"""Stop all other threads since web server is trying to exit."""
setup.stop()
def run():
def run(on_web_server_stop):
"""Start the web server and block it until exit."""
cherrypy.engine.start()
cherrypy.engine.subscribe('stop', on_server_stop)
cherrypy.engine.subscribe('stop', on_web_server_stop)
cherrypy.engine.block()