A
Andreas Tawn
I'm trying to integrate the timeout function from here
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/473878 into a
long running automation script and the following code causes IDLE after
20 or 30 iterations in countTest.
This is in 2.5, XP and there's no traceback.
Could someone point me at the user error?
Thanks in advance.
def countTest():
for i in xrange(10000000):
print i
return True
def timeout(func, args=(), kwargs={}, timeout_duration=1, default=None):
import threading
class InterruptableThread(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.result = None
def run(self):
try:
self.result = func(*args, **kwargs)
except:
self.result = default
it = InterruptableThread()
it.start()
it.join(timeout_duration)
if it.isAlive():
return default
else:
return it.result
def runTest():
timeout(countTest, timeout_duration=5)
if __name__ == "__main__":
runTest()
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/473878 into a
long running automation script and the following code causes IDLE after
20 or 30 iterations in countTest.
This is in 2.5, XP and there's no traceback.
Could someone point me at the user error?
Thanks in advance.
def countTest():
for i in xrange(10000000):
print i
return True
def timeout(func, args=(), kwargs={}, timeout_duration=1, default=None):
import threading
class InterruptableThread(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.result = None
def run(self):
try:
self.result = func(*args, **kwargs)
except:
self.result = default
it = InterruptableThread()
it.start()
it.join(timeout_duration)
if it.isAlive():
return default
else:
return it.result
def runTest():
timeout(countTest, timeout_duration=5)
if __name__ == "__main__":
runTest()