1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-12-23 01:16:18 +00:00

Prevent hanging transcoding processes on client disconnection

Fixes #55
This commit is contained in:
spl0k 2016-11-27 19:00:17 +01:00
parent 88458c70d5
commit 80e9e40248

View File

@ -92,6 +92,7 @@ def stream_media():
transcoder, decoder, encoder = map(lambda x: prepare_transcoding_cmdline(x, res.path, src_suffix, dst_suffix, dst_bitrate), [ transcoder, decoder, encoder ]) transcoder, decoder, encoder = map(lambda x: prepare_transcoding_cmdline(x, res.path, src_suffix, dst_suffix, dst_bitrate), [ transcoder, decoder, encoder ])
try: try:
if transcoder: if transcoder:
dec_proc = None
proc = subprocess.Popen(transcoder, stdout = subprocess.PIPE) proc = subprocess.Popen(transcoder, stdout = subprocess.PIPE)
else: else:
dec_proc = subprocess.Popen(decoder, stdout = subprocess.PIPE) dec_proc = subprocess.Popen(decoder, stdout = subprocess.PIPE)
@ -100,12 +101,19 @@ def stream_media():
return request.error_formatter(0, 'Error while running the transcoding process') return request.error_formatter(0, 'Error while running the transcoding process')
def transcode(): def transcode():
while True: try:
data = proc.stdout.read(8192) while True:
if not data: data = proc.stdout.read(8192)
break if not data:
yield data break
proc.terminate() yield data
except:
if dec_proc != None:
dec_proc.terminate()
proc.terminate()
if dec_proc != None:
dec_proc.wait()
proc.wait() proc.wait()
app.logger.info('Transcoding track {0.id} for user {1.id}. Source: {2} at {0.bitrate}kbps. Dest: {3} at {4}kbps'.format(res, request.user, src_suffix, dst_suffix, dst_bitrate)) app.logger.info('Transcoding track {0.id} for user {1.id}. Source: {2} at {0.bitrate}kbps. Dest: {3} at {4}kbps'.format(res, request.user, src_suffix, dst_suffix, dst_bitrate))