diff --git a/auto_rx/autorx/scan.py b/auto_rx/autorx/scan.py index 478711a..050be6f 100644 --- a/auto_rx/autorx/scan.py +++ b/auto_rx/autorx/scan.py @@ -865,12 +865,16 @@ class SondeScanner(object): self.log_warning("SDR produced no output... resetting and retrying.") self.error_retries += 1 # Attempt to reset the SDR, if possible. - reset_sdr( - self.sdr_type, - rtl_device_idx = self.rtl_device_idx, - sdr_hostname = self.sdr_hostname, - sdr_port = self.sdr_port - ) + try: + reset_sdr( + self.sdr_type, + rtl_device_idx = self.rtl_device_idx, + sdr_hostname = self.sdr_hostname, + sdr_port = self.sdr_port + ) + except Exception as e: + self.log_error(f"Caught error when trying to reset SDR - {str(e)}") + for _ in range(10): if not self.sonde_scanner_running: break diff --git a/auto_rx/autorx/web.py b/auto_rx/autorx/web.py index 34a40b9..1455a3c 100644 --- a/auto_rx/autorx/web.py +++ b/auto_rx/autorx/web.py @@ -290,7 +290,11 @@ def shutdown_flask(shutdown_key): global flask_shutdown_key # Only shutdown if the supplied key matches our shutdown key if shutdown_key == flask_shutdown_key: - flask.request.environ.get("werkzeug.server.shutdown")() + shutdown_function = flask.request.environ.get("werkzeug.server.shutdown") + if shutdown_function: + shutdown_function() + else: + logging.debug("Unable to stop this version of Werkzeug, continuing...") return "" @@ -586,6 +590,8 @@ def start_flask(host="0.0.0.0", port=5000): # Start up Flask flask_app_thread = Thread(target=flask_thread, kwargs={"host": host, "port": port}) + # Set thread to be a daemon, so python will quit nicely. + flask_app_thread.daemon = True flask_app_thread.start() logging.info("Started Flask server on http://%s:%d" % (host, port))