> > On Dec 5, 6:00 am, "Andreas Tawn" <[EMAIL PROTECTED]> wrote: > > > I'm trying to integrate the timeout function from > > herehttp://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/47 > > 3878into 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() > > > > I'm confused. What does it cause IDLE to do? I tried running the > > script and it ran fine. I killed it 17346 since I have no > intention of > > letting it tie up my work for your extraordinary large iteration > > number. > > > > I'm using Python 2.4 on Windows XP. > > > > Mike > > Sorry, I need a better proof-reader. > > When I run that code, the output gets to ~26 and then IDLE (or the > shell, I'm not sure which) hangs and there's zero CPU activity in the > pythonw.exe process.
Also, I should say that the the idea is that the huge iteration should timeout after 5 seconds. I only gave it a 10000000 range because I didn't know how fast it would get through the loop. Perhaps you stopped it before the timeout triggered? Cheers, Drea -- http://mail.python.org/mailman/listinfo/python-list