def function(message):
if 'START' in message:
timer = 10
#start a thread which sleeps for 'timer' and prints "TIMER EXPIRED"
if 'STOP' in message:
#check if timer is still running, terminate thread if yes (print "TIMER STOPPED")
def main():
function('START')
time.sleep(random_time)
function('STOP')
1.please suggest what kind of thread is best for this program, thread.start_new_thread() doesn’t seem to have exit() or terminate() from main program.
2.how to make sure timer is still running and then terminate thred
need to work with threads since,Process gives an error saying the new process is not able to use variables from old one, i am actually calling other functions rather than printing ‘TIMER EXPIRED’ and ‘TIMER STOPPED’
Here is the code used to stop thread started in previous function call.
In the first iteration, start thread and pass the reference(i made it global variable)
global t1, t1_stop
def timer_run(timer_val):
def funct():
def main():