main.py: secured queue_processor with try/except due to receiving multiple None messages, will try to figure out what is broken there

This commit is contained in:
dymik739 2022-11-05 21:47:16 +02:00
parent a1d76d3bad
commit eb51a5d2ee
1 changed files with 42 additions and 33 deletions

View File

@ -155,6 +155,7 @@ class ModuleControlUnit:
# synchronous message processor # synchronous message processor
def queue_processor(): def queue_processor():
while True: while True:
try:
if len(message_queue) > 0: if len(message_queue) > 0:
msg = message_queue[0] msg = message_queue[0]
print("[DEBUG] queue_processor: {}".format(msg)) # debug print("[DEBUG] queue_processor: {}".format(msg)) # debug
@ -189,6 +190,14 @@ def queue_processor():
break break
else: else:
time.sleep(1) time.sleep(1)
except Exception as e:
print("[ERROR] queue_processor: current message queue: {}".format(message_queue))
print("[ERROR] queue_processor: error while processing message, trying to delete it...")
try:
del message_queue[0]
print("[INFO] queue_processor: deleted broken message from the queue")
except:
print("[WARN] queue_processor: message seems absent, whatever")
print("[INFO] queue_processor thread stops successfully") print("[INFO] queue_processor thread stops successfully")