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:
parent
88458c70d5
commit
80e9e40248
@ -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():
|
||||||
|
try:
|
||||||
while True:
|
while True:
|
||||||
data = proc.stdout.read(8192)
|
data = proc.stdout.read(8192)
|
||||||
if not data:
|
if not data:
|
||||||
break
|
break
|
||||||
yield data
|
yield data
|
||||||
|
except:
|
||||||
|
if dec_proc != None:
|
||||||
|
dec_proc.terminate()
|
||||||
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))
|
||||||
|
Loading…
Reference in New Issue
Block a user