I am very new to python and programming in general and am trying to build a loop that can be cancelled when the timer ends or cancelled by a variable that will be set externally. I am testing with my code below and it doesn't want to cancel, like it never re-reads the variable to realize that it is no longer a 1. It seems like I am either really close or way off.
Code:
import threading
scalavar = 1
enable = 1
def disable():
scalavar=0
print 'timer stop'
timer = threading.Timer(5,disable)
timer.start()
while (enable == 1):
if (enable == 1):
print 'working'
enable=scalavar
elif (enable != 1):
break
print 'Goodbye'
Comment