More robust logic on the bus in case the message failed to parse (prevents the application from crashing)

This commit is contained in:
Fabio Manganiello 2020-09-09 02:15:35 +02:00
parent a650840429
commit 1e972ded99
1 changed files with 2 additions and 1 deletions

View File

@ -58,7 +58,8 @@ class Bus(object):
stop = False
while not stop:
msg = self.get()
if msg.timestamp and time.time() - msg.timestamp > self._MSG_EXPIRY_TIMEOUT:
timestamp = msg.timestamp if hasattr(msg, 'timestamp') else msg.get('timestamp')
if timestamp and time.time() - timestamp > self._MSG_EXPIRY_TIMEOUT:
logger.debug('{} seconds old message on the bus expired, ignoring it: {}'.
format(int(time.time()-msg.timestamp), msg))
continue