clean up .wav files on exception, refs #107

This commit is contained in:
Jakob Ketterl 2020-05-11 23:20:03 +02:00
parent a94209a2bc
commit 2483398b0f

View File

@ -25,6 +25,12 @@ class QueueJob(object):
def run(self): def run(self):
self.decoder.decode(self) self.decoder.decode(self)
def unlink(self):
try:
os.unlink(self.file)
except FileNotFoundError:
pass
class QueueWorker(threading.Thread): class QueueWorker(threading.Thread):
def __init__(self, queue): def __init__(self, queue):
@ -40,6 +46,9 @@ class QueueWorker(threading.Thread):
except Exception: except Exception:
logger.exception("failed to decode job") logger.exception("failed to decode job")
self.queue.onError() self.queue.onError()
finally:
job.unlink()
self.queue.task_done() self.queue.task_done()
@ -159,11 +168,12 @@ class AudioWriter(object):
self.switchingLock.release() self.switchingLock.release()
file.close() file.close()
job = QueueJob(self, filename, self.dsp.get_operating_freq())
try: try:
DecoderQueue.getSharedInstance().put(QueueJob(self, filename, self.dsp.get_operating_freq())) DecoderQueue.getSharedInstance().put(job)
except Full: except Full:
logger.warning("decoding queue overflow; dropping one file") logger.warning("decoding queue overflow; dropping one file")
os.unlink(filename) job.unlink()
self._scheduleNextSwitch() self._scheduleNextSwitch()
def decode(self, job: QueueJob): def decode(self, job: QueueJob):
@ -183,7 +193,6 @@ class AudioWriter(object):
except subprocess.TimeoutExpired: except subprocess.TimeoutExpired:
logger.warning("subprocess (pid=%i}) did not terminate correctly; sending kill signal.", decoder.pid) logger.warning("subprocess (pid=%i}) did not terminate correctly; sending kill signal.", decoder.pid)
decoder.kill() decoder.kill()
os.unlink(job.file)
def start(self): def start(self):
(self.wavefilename, self.wavefile) = self.getWaveFile() (self.wavefilename, self.wavefile) = self.getWaveFile()