From 53612d39ceba95001b545bbc653673259bc2648b Mon Sep 17 00:00:00 2001 From: Greg Albrecht Date: Tue, 24 Dec 2024 13:49:21 -0800 Subject: [PATCH] added timeout for gps fix --- dronecot/functions.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/dronecot/functions.py b/dronecot/functions.py index 5109635..ac30cc6 100644 --- a/dronecot/functions.py +++ b/dronecot/functions.py @@ -20,7 +20,7 @@ import asyncio import json -import os +import subprocess import xml.etree.ElementTree as ET from configparser import SectionProxy @@ -364,9 +364,13 @@ def get_gps_info(config) -> Optional[dict]: gpspipe_data: Optional[str] = None gps_data: Optional[str] = None gps_info_cmd = config.get("GPS_INFO_CMD", dronecot.DEFAULT_GPS_INFO_CMD) - - with os.popen(gps_info_cmd) as gps_info_cmd: - gpspipe_data = gps_info_cmd.read() + try: + gpspipe_data = subprocess.check_output( + gps_info_cmd, shell=True, timeout=10 + ).decode() + except subprocess.TimeoutExpired: + print("Unable to get GPS fix, ignoring.") + return None if not gpspipe_data: return None