I have a callback function but the delegate that issues the callback occasionally takes several seconds to provides updates (because it is waiting for data over a remote connection). For my use case this is troublesome because I need to run a function at a regular time, or quit the program. What is the easiest way to have a timer in python that runs a function, or quits the application if I haven't had an update from the delegate within a certain space of time, like five seconds?
def parseMessage(client, userdata, message): # CALLBACK FUNCTION THAT LISTENS FOR NEW MESSAGES
signal = int(str(message.payload.decode("utf-8")))
writeToSerial(signal)
def exceptionState(): # THIS IS THE FUNCTION I WOULD LIKE TO RUN IF THERE'S NO CALLBACK
print("ERROR, LINK IS DOWN, DISABLING SERVER")
exit()
def mqttSignal():
client.on_message = parseMessage # THIS INVOKES THE CALLBACK FUNCTION
client.loop_forever()