Timeout test hangs IDLE

kyosohma at gmail.com kyosohma at gmail.com
Wed Dec 5 09:15:52 EST 2007


On Dec 5, 6:00 am, "Andreas Tawn" <andreas.t... at ubisoft.com> wrote:
> I'm trying to integrate the timeout function from herehttp://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/473878into 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



More information about the Python-list mailing list