diff --git a/csdr.py b/csdr.py index 616cb25..1807fe0 100755 --- a/csdr.py +++ b/csdr.py @@ -26,6 +26,7 @@ import os import code import signal import fcntl +import threading class dsp: @@ -282,6 +283,8 @@ class dsp: return float(line[:-1]) except ValueError: return 0 + else: + time.sleep(1) def mkfifo(self,path): try: @@ -351,6 +354,15 @@ class dsp: if self.csdr_dynamic_bufsize: my_env["CSDR_DYNAMIC_BUFSIZE_ON"]="1"; if self.csdr_print_bufsizes: my_env["CSDR_PRINT_BUFSIZES"]="1"; self.process = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True, preexec_fn=os.setpgrp, env=my_env) + + def watch_thread(): + rc = self.process.wait() + print("dsp thread ended with rc={0}".format(rc)) + if (self.running): + self.restart() + + threading.Thread(target = watch_thread).start() + self.running = True #open control pipes for csdr and send initialization data @@ -372,7 +384,13 @@ class dsp: return self.process.stdout.read(size) def stop(self): - os.killpg(os.getpgid(self.process.pid), signal.SIGTERM) + self.running = False + if hasattr(self, "process"): + try: + os.killpg(os.getpgid(self.process.pid), signal.SIGTERM) + except ProcessLookupError: + # been killed by something else, ignore + pass self.stop_secondary_demodulator() #if(self.process.poll()!=None):return # returns None while subprocess is running #while(self.process.poll()==None): @@ -403,8 +421,6 @@ class dsp: # try: os.unlink(self.iqtee2_pipe) # except: print "[openwebrx-dsp-plugin:csdr] stop() :: unlink failed: " + self.iqtee2_pipe - self.running = False - def restart(self): self.stop() self.start() diff --git a/owrx/controllers.py b/owrx/controllers.py index 7c8e615..21c0801 100644 --- a/owrx/controllers.py +++ b/owrx/controllers.py @@ -72,6 +72,7 @@ class WebSocketMessageHandler(object): def __init__(self): self.handshake = None self.client = None + self.dsp = None def handleTextMessage(self, conn, message): pm = PropertyManager.getSharedInstance() diff --git a/owrx/source.py b/owrx/source.py index 872ee36..832cd1e 100644 --- a/owrx/source.py +++ b/owrx/source.py @@ -126,11 +126,12 @@ class SpectrumThread(threading.Thread): while self.doRun: data=dsp.read(bytes_to_read) if len(data) == 0: - self.shutdown() + time.sleep(1) else: for c in self.clients: c.write_spectrum_data(data) + dsp.stop() print("spectrum thread shut down") def add_client(self, c):