diff --git a/aircox/controllers.py b/aircox/controllers.py index e203b01..c39d19a 100755 --- a/aircox/controllers.py +++ b/aircox/controllers.py @@ -136,6 +136,26 @@ class Streamer: """ return ['liquidsoap', '-v', self.path] + def __check_for_zombie(self): + """ + Check if there is a process that has not been killed + """ + # TODO: this method does not work in case the working + # directory has been erased then regenerated + if not os.path.exist(self.path + ".pid"): + return + + with open(self.path + ".pid") as file: + pid = file.read() + os.kill(int(pid), signal.SIGKILL) + + def __prevent_zombie(self): + """ + Write process pid + """ + with open(self.path + ".pid", "w") as file: + file.write(str(self.process.pid)) + def process_run(self): """ Execute the external application with corresponding informations. @@ -150,7 +170,10 @@ class Streamer: args = self.__get_process_args() if not args: return + + self.__check_for_zombie() self.process = subprocess.Popen(args, stderr=subprocess.STDOUT) + self.__prevent_zombie() atexit.register(lambda: self.process_terminate()) def process_terminate(self): @@ -162,6 +185,9 @@ class Streamer: self.process.kill() self.process = None + # the zombie has been killed + os.remove(self.path + ".pid") + def process_wait(self): """ Wait for the process to terminate if there is a process diff --git a/aircox/management/commands/streamer.py b/aircox/management/commands/streamer.py index 9be32d6..5352466 100755 --- a/aircox/management/commands/streamer.py +++ b/aircox/management/commands/streamer.py @@ -6,6 +6,8 @@ used to: - cancels Diffusions that have an archive but could not have been played; - run Liquidsoap """ +import os +import signal import time import re diff --git a/aircox/views.py b/aircox/views.py index 05077a2..d5dd4f9 100755 --- a/aircox/views.py +++ b/aircox/views.py @@ -111,7 +111,7 @@ class Monitor(View,TemplateResponseMixin,LoginRequiredMixin): source = None if 'source' in POST: source = [ s for s in station.sources - if s.name == POST['source']] + if s.name == POST['source'] ] source = source[0] if not source: return Http404 diff --git a/aircox_cms/sections.py b/aircox_cms/sections.py index 908db98..d2bcbc8 100755 --- a/aircox_cms/sections.py +++ b/aircox_cms/sections.py @@ -931,7 +931,6 @@ class SectionLogsList(SectionItem): Supports: Log/Track, Diffusion """ from aircox_cms.models import DiffusionPage - print(log, type(log)) if type(log) == aircox.models.Diffusion: return DiffusionPage.as_item(log)