Switch to monotonic time

fix/aprs-performance
xss 2022-03-01 10:01:15 +11:00
rodzic fe786b038b
commit 668d4ea141
1 zmienionych plików z 3 dodań i 6 usunięć

Wyświetl plik

@ -89,9 +89,6 @@ def telemetry_to_aprs_position(
# TODO: RS41 Burst Timer # TODO: RS41 Burst Timer
# Add on auto_rx at the end
_aprs_comment += " auto_rx"
# Convert float latitude to APRS format (DDMM.MM) # Convert float latitude to APRS format (DDMM.MM)
lat = float(sonde_data["lat"]) lat = float(sonde_data["lat"])
lat_degree = abs(int(lat)) lat_degree = abs(int(lat))
@ -361,7 +358,7 @@ class APRSUploader(object):
self.upload_timeout = upload_timeout self.upload_timeout = upload_timeout
self.upload_queue_size = upload_queue_size self.upload_queue_size = upload_queue_size
self.upload_time = upload_time self.upload_time = upload_time
self.next_upload = datetime.datetime.now() + datetime.timedelta(seconds=upload_time) self.next_upload = time.monotonic() + upload_time
self.callsign_validity_threshold = callsign_validity_threshold self.callsign_validity_threshold = callsign_validity_threshold
self.inhibit = inhibit self.inhibit = inhibit
@ -652,7 +649,7 @@ class APRSUploader(object):
""" Add packets to the aprs upload queue if it is time for us to upload. """ """ Add packets to the aprs upload queue if it is time for us to upload. """
while self.timer_thread_running: while self.timer_thread_running:
if datetime.datetime.now() > self.next_upload: if time.monotonic() > self.next_upload:
# Time to upload! # Time to upload!
for _id in self.observed_payloads.keys(): for _id in self.observed_payloads.keys():
# If no data, continue... # If no data, continue...
@ -678,7 +675,7 @@ class APRSUploader(object):
self.flush_rx() self.flush_rx()
# Reset upload timer # Reset upload timer
self.next_upload = datetime.datetime.now() + datetime.timedelta(seconds=self.upload_time) self.next_upload = time.monotonic() + self.upload_time
else: else:
# Not yet time to upload, wait for a bit. # Not yet time to upload, wait for a bit.
time.sleep(0.1) time.sleep(0.1)