From e3854b524853f38005b625d34885d5956529de83 Mon Sep 17 00:00:00 2001 From: Matthew Stratford Date: Thu, 2 Sep 2021 00:10:32 +0100 Subject: [PATCH] Change order of shutdown to shorten audio gap --- server.py | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/server.py b/server.py index f92f07d..89f8d05 100644 --- a/server.py +++ b/server.py @@ -242,15 +242,19 @@ class BAPSicleServer: self.websockets_server.join(timeout=PROCESS_KILL_TIMEOUT_S) del self.websockets_server - print("Stopping Players") - for q in self.player_to_q: - q.put("ALL:QUIT") + print("Stopping File Manager") + if self.file_manager: + self.file_manager.terminate() + self.file_manager.join(timeout=PROCESS_KILL_TIMEOUT_S) + del self.file_manager - for player in self.player: - player.join(timeout=PROCESS_KILL_TIMEOUT_S) - - del self.player + print("Stopping Controllers") + if self.controller_handler: + self.controller_handler.terminate() + self.controller_handler.join(timeout=PROCESS_KILL_TIMEOUT_S) + del self.controller_handler + # Stop the Webserver late as we can to allow Presenter to pull images for the disconnection page if it needs to. print("Stopping Web Server") if self.webserver: self.webserver.terminate() @@ -263,17 +267,16 @@ class BAPSicleServer: self.player_handler.join(timeout=PROCESS_KILL_TIMEOUT_S) del self.player_handler - print("Stopping File Manager") - if self.file_manager: - self.file_manager.terminate() - self.file_manager.join(timeout=PROCESS_KILL_TIMEOUT_S) - del self.file_manager + # Now we've stopped everything else, now is the time to stop the players. This is to keep playing for as long as possible during a restart. + print("Stopping Players") + for q in self.player_to_q: + q.put("ALL:QUIT") + + for player in self.player: + player.join(timeout=PROCESS_KILL_TIMEOUT_S) + + del self.player - print("Stopping Controllers") - if self.controller_handler: - self.controller_handler.terminate() - self.controller_handler.join(timeout=PROCESS_KILL_TIMEOUT_S) - del self.controller_handler print("Stopped all processes.")