I am trying to implement a threaded timer to control a timeout for a serial process.
def tst_setMaxTimeFlag():
lock.acquire()
maxTimeFlag = 1
lock.release()
print "timeout!"
return
def tst_setMaxTimeTimer(maxResponseTime):
global responseTimer
lock.acquire()
maxTimeFlag = 0
lock.release()
responseTimer = threading.Timer(2,tst_setMaxTimeFlag)
print "timer set!"
responseTimer.start
print "timer start!"
return
I would imagine the output to be:
- timer set
- timer start
- timeout!
However, the tst_setMaxTimeFlag() is never called and timeout! is never printed.
If I alter responseTimer = threading.Timer(2,tst_setMaxTimeFlag) to responseTimer = threading.Timer(2,tst_setMaxTimeFlag()) the timeout function is called immediately regardless of the time parameter.
maxTimeFlag is set as a global in main and initialized to 0.
Any thoughts?