fix thread leak

This commit is contained in:
Jakob Ketterl 2021-08-26 17:21:52 +02:00
parent aecb79a4d4
commit ee3d934529

View File

@ -192,23 +192,22 @@ class DspManager(Output, SdrSourceEventClient):
self.props["audio_compression"] self.props["audio_compression"]
) )
self.readers = []
# wire audio output # wire audio output
buffer = Buffer(self.chain.getOutputFormat()) buffer = Buffer(self.chain.getOutputFormat())
self.chain.setWriter(buffer) self.chain.setWriter(buffer)
reader = buffer.getReader() self.wireOutput("audio", buffer)
self.send_output("audio", reader.read)
# wire power level output # wire power level output
buffer = Buffer(Format.FLOAT) buffer = Buffer(Format.FLOAT)
self.chain.setPowerWriter(buffer) self.chain.setPowerWriter(buffer)
reader = buffer.getReader() self.wireOutput("smeter", buffer)
self.send_output("smeter", reader.read)
# wire meta output # wire meta output
buffer = Buffer(Format.CHAR) buffer = Buffer(Format.CHAR)
self.chain.setMetaWriter(buffer) self.chain.setMetaWriter(buffer)
reader = buffer.getReader() self.wireOutput("meta", buffer)
self.send_output("meta", reader.read)
def set_dial_freq(changes): def set_dial_freq(changes):
if ( if (
@ -329,8 +328,8 @@ class DspManager(Output, SdrSourceEventClient):
else: else:
self.startOnAvailable = True self.startOnAvailable = True
def receive_output(self, t, read_fn): def wireOutput(self, t: str, buffer: Buffer):
logger.debug("adding new output of type %s", t) logger.debug("wiring new output of type %s", t)
writers = { writers = {
"audio": self.handler.write_dsp_data, "audio": self.handler.write_dsp_data,
"hd_audio": self.handler.write_hd_audio, "hd_audio": self.handler.write_hd_audio,
@ -343,11 +342,15 @@ class DspManager(Output, SdrSourceEventClient):
write = writers[t] write = writers[t]
threading.Thread(target=self.pump(read_fn, write), name="dsp_pump_{}".format(t)).start() reader = buffer.getReader()
self.readers.append(reader)
threading.Thread(target=self.pump(reader.read, write), name="dsp_pump_{}".format(t)).start()
def stop(self): def stop(self):
self.chain.stop() self.chain.stop()
self.chain = None self.chain = None
while self.readers:
self.readers.pop().stop()
self.startOnAvailable = False self.startOnAvailable = False
self.sdrSource.removeClient(self) self.sdrSource.removeClient(self)