kill process the hard way in controllers.py

This commit is contained in:
bkfox 2017-01-09 14:09:37 +01:00
parent 7f1a5c0193
commit 85d861fdb4
2 changed files with 9 additions and 3 deletions

View File

@ -2,6 +2,7 @@ import os
import re
import subprocess
import atexit
import logging
from django.template.loader import render_to_string
@ -10,6 +11,8 @@ import aircox.settings as settings
from aircox.connector import Connector
logger = logging.getLogger('aircox.tools')
class Streamer:
"""
@ -148,11 +151,15 @@ class Streamer:
if not args:
return
self.process = subprocess.Popen(args, stderr=subprocess.STDOUT)
atexit.register(self.process.terminate)
atexit.register(lambda: self.process_terminate())
def process_terminate(self):
if self.process:
self.process.terminate()
logger.info("kill process {pid}: {info}".format(
pid = self.process.pid,
info = ' '.join(self.__get_process_args())
))
self.process.kill()
self.process = None
def process_wait(self):

View File

@ -6,7 +6,6 @@ used to:
- cancels Diffusions that have an archive but could not have been played;
- run Liquidsoap
"""
import os
import time
import re