From f310d501f4c5305fbe4577030ea4adf8178812ec Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Tue, 1 Aug 2023 12:31:04 -0700 Subject: [PATCH] rawgpsd: better download proc cleanup (#29199) * rawgpsd: better download proc cleanup * more * cleanup --------- Co-authored-by: Comma Device --- system/sensord/rawgps/rawgpsd.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/system/sensord/rawgps/rawgpsd.py b/system/sensord/rawgps/rawgpsd.py index 5db6ad1cf5..829d7bed08 100755 --- a/system/sensord/rawgps/rawgpsd.py +++ b/system/sensord/rawgps/rawgpsd.py @@ -144,9 +144,13 @@ def download_assistance(): def downloader_loop(event): if os.path.exists(ASSIST_DATA_FILE): os.remove(ASSIST_DATA_FILE) - while not os.path.exists(ASSIST_DATA_FILE) and not event.is_set(): - download_assistance() - time.sleep(10) + + try: + while not os.path.exists(ASSIST_DATA_FILE) and not event.is_set(): + download_assistance() + event.wait(timeout=10) + except KeyboardInterrupt: + pass def inject_assistance(): for _ in range(5): @@ -259,14 +263,20 @@ def main() -> NoReturn: stop_download_event = Event() assist_fetch_proc = Process(target=downloader_loop, args=(stop_download_event,)) assist_fetch_proc.start() - def cleanup(proc): + def cleanup(sig, frame): cloudlog.warning("caught sig disabling quectel gps") + gpio_set(GPIO.UBLOX_PWR_EN, False) teardown_quectel(diag) cloudlog.warning("quectel cleanup done") + + stop_download_event.set() + assist_fetch_proc.kill() + assist_fetch_proc.join() + sys.exit(0) - signal.signal(signal.SIGINT, lambda sig, frame: cleanup(assist_fetch_proc)) - signal.signal(signal.SIGTERM, lambda sig, frame: cleanup(assist_fetch_proc)) + signal.signal(signal.SIGINT, cleanup) + signal.signal(signal.SIGTERM, cleanup) # connect to modem diag = ModemDiag()