Is there a way to start the Timer in the callback function? I want to do something like this:
senderSocket.sendall(message)
t = Timer(5, lambda senderSocket, message: senderSocket.sendall(message), (senderSocket, message))
t.start()
recv = senderSocket.recv(1024).decode("utf-8")
Essentially, I start a timer after sending a message to the receiver and I expect a reply from the receiver. If I do not receive a reply, then I want to resend the message to the receiver and restart the timer. I want to keep this going until I get a reply. But, I am not able to figure out how to restart the timer.
Since the line: recv = senderSocket.recv(1024).decode("utf-8")
blocks the code, I cannot add the start timer line after this line and the only way I can think of restarting the timer is to restart it from within the callback function after resending the message. How can I do that? Or is there any other way of restarting the Timer?