diff --git a/modem/daemon.py b/modem/daemon.py index cec3eb06..f8cc3889 100755 --- a/modem/daemon.py +++ b/modem/daemon.py @@ -32,7 +32,6 @@ import structlog import ujson as json import config - # signal handler for closing application def signal_handler(sig, frame): """ @@ -77,6 +76,44 @@ class DAEMON: worker = threading.Thread(target=self.worker, name="WORKER", daemon=True) worker.start() + rigctld_watchdog_thread = threading.Thread(target=self.rigctld_watchdog, name="WORKER", daemon=True) + rigctld_watchdog_thread.start() + + + def rigctld_watchdog(self): + """ + Check for rigctld status + Returns: + + """ + while True: + threading.Event().wait(0.3) + # only continue, if we have a process object initialized + if hasattr(Daemon.rigctldprocess, "returncode"): + + if Daemon.rigctldprocess.returncode in [None, "None"] or not Daemon.rigctldstarted: + Daemon.rigctldstarted = True + outs, errs = Daemon.rigctldprocess.communicate(timeout=30) + print(f"outs: {outs}") + print(f"errs: {errs}") + #print(Daemon.rigctldprocess.stderr.read()) + else: + self.log.warning("[DMN] [RIGCTLD] [Watchdog] returncode detected",process=Daemon.rigctldprocess) + Daemon.rigctldstarted = False + # triggering another kill + Daemon.rigctldprocess.kill() + # erase process object + Daemon.rigctldprocess = None + else: + Daemon.rigctldstarted = False + + #try: + # outs, errs = proc.communicate(timeout=15) + #except TimeoutExpired: + # proc.kill() + # outs, errs = proc.communicate() + + def update_audio_devices(self): """ Update audio devices and set to static @@ -374,7 +411,7 @@ class DAEMON: self.log.info("[DMN] starting rigctld: ", param=command) if not isWin: - proc = subprocess.Popen(command, stdout=subprocess.PIPE) + proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) else: #On windows, open rigctld in new window for easier troubleshooting proc = subprocess.Popen(command, creationflags=subprocess.CREATE_NEW_CONSOLE,close_fds=True) diff --git a/modem/sock.py b/modem/sock.py index ca12e599..a222d440 100644 --- a/modem/sock.py +++ b/modem/sock.py @@ -1144,6 +1144,9 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler): try: log.warning("[SCK] Stopping Modem") Daemon.modemstarted = False + # we need to run this twice, otherwise process won't be stopped + Daemon.modemprocess.kill() + threading.Event().wait(0.3) Daemon.modemprocess.kill() # unregister process from atexit to avoid process zombies atexit.unregister(Daemon.modemprocess.kill)