From fa6e591ca9c582f41cb97a091316a63a322619a5 Mon Sep 17 00:00:00 2001 From: DJ2LS Date: Mon, 13 May 2024 11:41:06 +0200 Subject: [PATCH] work on server shutdown.. --- freedata_server/schedule_manager.py | 4 +++- freedata_server/server.py | 19 ++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/freedata_server/schedule_manager.py b/freedata_server/schedule_manager.py index 2e873332..496cf20e 100644 --- a/freedata_server/schedule_manager.py +++ b/freedata_server/schedule_manager.py @@ -7,6 +7,8 @@ from message_system_db_messages import DatabaseManagerMessages from message_system_db_beacon import DatabaseManagerBeacon import explorer import command_beacon +import atexit + class ScheduleManager: @@ -39,7 +41,7 @@ class ScheduleManager: """Start scheduling events and run the scheduler in a separate thread.""" # wait some time - threading.Event().wait(timeout=10) + #threading.Event().wait(timeout=10) # get actual freedata_server instance self.modem = modem diff --git a/freedata_server/server.py b/freedata_server/server.py index 4e062702..2ae4793d 100644 --- a/freedata_server/server.py +++ b/freedata_server/server.py @@ -26,6 +26,7 @@ import command_arq_raw import command_message_send import event_manager import atexit +import threading from message_system_db_manager import DatabaseManager from message_system_db_messages import DatabaseManagerMessages @@ -345,14 +346,17 @@ def sock_states(sock): def stop_server(): print("------------------------------------------") # TODO This is causing problems for some reasons. - #if "service_manager" : - # app.service_manager.modem_service.put("stop") - # if app.socket_interface_manager: - # app.socket_interface_manager.stop_servers() + if hasattr(app, 'service_manager'): + if hasattr(app, 'socket_interface_manager') and app.socket_interface_manager: + app.socket_interface_manager.stop_servers() - # if app.service_manager.modem: - # app.service_manager.modem.sd_input_stream.stop - #time.sleep(1) + if hasattr(app.service_manager, 'modem_service') and app.service_manager.modem_service: + app.service_manager.modem_service.put("stop") + + if hasattr(app.service_manager, 'modem') and app.service_manager.modem: + app.service_manager.modem.sd_input_stream.stop + + threading.Event().wait(2) def main(): app.config['SOCK_SERVER_OPTIONS'] = {'ping_interval': 10} @@ -395,5 +399,6 @@ def main(): app.run(modemaddress, modemport, debug=False) + if __name__ == "__main__": main()