Cancellable threading.Timer in Python
You would call the cancel method after you start the timer: import time import threading def hello(): print “hello, world” time.sleep(2) t = threading.Timer(3.0, hello) t.start() var=”something” if var == ‘something’: t.cancel() You might consider using a while-loop on a Thread, instead of using a Timer. Here is an example appropriated from Nikolaus Gradwohl’s answer … Read more