SubMaster: replace SIMULATION constant with property (#495)

* Add simulation property to python submaster

* decode bstrings before formatting error messages
This commit is contained in:
Kacper Rączy
2023-07-12 04:30:00 +02:00
committed by GitHub
parent c94c7c61cc
commit a2f1f0cb8d
2 changed files with 5 additions and 5 deletions

View File

@@ -20,7 +20,6 @@ assert wait_for_one_event
NO_TRAVERSAL_LIMIT = 2**64-1
AVG_FREQ_HISTORY = 100
SIMULATION = "SIMULATION" in os.environ
# sec_since_boot is faster, but allow to run standalone too
try:
@@ -179,6 +178,7 @@ class SubMaster:
self.ignore_average_freq = [] if ignore_avg_freq is None else ignore_avg_freq
self.ignore_alive = [] if ignore_alive is None else ignore_alive
self.simulation = bool(int(os.getenv("SIMULATION", "0")))
for s in services:
if addr is not None:
@@ -231,11 +231,11 @@ class SubMaster:
self.logMonoTime[s] = msg.logMonoTime
self.valid[s] = msg.valid
if SIMULATION:
if self.simulation:
self.freq_ok[s] = True
self.alive[s] = True
if not SIMULATION:
if not self.simulation:
for s in self.data:
# arbitrary small number to avoid float comparison. If freq is 0, we can skip the check
if self.freq[s] > 1e-5:

View File

@@ -20,8 +20,8 @@ from .messaging cimport Event as cppEvent, SocketEventHandle as cppSocketEventHa
class MessagingError(Exception):
def __init__(self, endpoint=None):
suffix = "with {endpoint}" if endpoint else ""
message = f"Messaging failure {suffix}: {strerror(errno.errno)}"
suffix = f"with {endpoint.decode('utf-8')}" if endpoint else ""
message = f"Messaging failure {suffix}: {strerror(errno.errno).decode('utf-8')}"
super().__init__(message)