Lets say I have a function 'demo()' performing some task. This function takes 1 min to execute. But some times this function takes over 5 mins to execute. I want to make it such that if this function keeps running of over 3 mins, it should skip the current loop iteration and go to the next loop iteration.
Code:
while True:
demo(input)
I thought of using 'time' module but I could only come up with this:
import time
while True:
start_time = time.time()
demo(input)
elapsed_time = time.time() - start_time
if elapsed_time > 180: # 180 seconds = 3 minutes
continue
But this won't work since the code after the function wont be executed until demo() has been executed.
I couldn't find a solution to this. Any suggestions are appreciated, thank you.