forked from rc/aircox
kill zombie liquidsoap
This commit is contained in:
parent
7d315ea002
commit
bf616fac67
|
@ -136,6 +136,26 @@ class Streamer:
|
||||||
"""
|
"""
|
||||||
return ['liquidsoap', '-v', self.path]
|
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):
|
def process_run(self):
|
||||||
"""
|
"""
|
||||||
Execute the external application with corresponding informations.
|
Execute the external application with corresponding informations.
|
||||||
|
@ -150,7 +170,10 @@ class Streamer:
|
||||||
args = self.__get_process_args()
|
args = self.__get_process_args()
|
||||||
if not args:
|
if not args:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
self.__check_for_zombie()
|
||||||
self.process = subprocess.Popen(args, stderr=subprocess.STDOUT)
|
self.process = subprocess.Popen(args, stderr=subprocess.STDOUT)
|
||||||
|
self.__prevent_zombie()
|
||||||
atexit.register(lambda: self.process_terminate())
|
atexit.register(lambda: self.process_terminate())
|
||||||
|
|
||||||
def process_terminate(self):
|
def process_terminate(self):
|
||||||
|
@ -162,6 +185,9 @@ class Streamer:
|
||||||
self.process.kill()
|
self.process.kill()
|
||||||
self.process = None
|
self.process = None
|
||||||
|
|
||||||
|
# the zombie has been killed
|
||||||
|
os.remove(self.path + ".pid")
|
||||||
|
|
||||||
def process_wait(self):
|
def process_wait(self):
|
||||||
"""
|
"""
|
||||||
Wait for the process to terminate if there is a process
|
Wait for the process to terminate if there is a process
|
||||||
|
|
|
@ -6,6 +6,8 @@ used to:
|
||||||
- cancels Diffusions that have an archive but could not have been played;
|
- cancels Diffusions that have an archive but could not have been played;
|
||||||
- run Liquidsoap
|
- run Liquidsoap
|
||||||
"""
|
"""
|
||||||
|
import os
|
||||||
|
import signal
|
||||||
import time
|
import time
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
|
|
@ -111,7 +111,7 @@ class Monitor(View,TemplateResponseMixin,LoginRequiredMixin):
|
||||||
source = None
|
source = None
|
||||||
if 'source' in POST:
|
if 'source' in POST:
|
||||||
source = [ s for s in station.sources
|
source = [ s for s in station.sources
|
||||||
if s.name == POST['source']]
|
if s.name == POST['source'] ]
|
||||||
source = source[0]
|
source = source[0]
|
||||||
if not source:
|
if not source:
|
||||||
return Http404
|
return Http404
|
||||||
|
|
|
@ -931,7 +931,6 @@ class SectionLogsList(SectionItem):
|
||||||
Supports: Log/Track, Diffusion
|
Supports: Log/Track, Diffusion
|
||||||
"""
|
"""
|
||||||
from aircox_cms.models import DiffusionPage
|
from aircox_cms.models import DiffusionPage
|
||||||
print(log, type(log))
|
|
||||||
if type(log) == aircox.models.Diffusion:
|
if type(log) == aircox.models.Diffusion:
|
||||||
return DiffusionPage.as_item(log)
|
return DiffusionPage.as_item(log)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user