Limiting execution time of a function call in Python kills my Kernel <p>I need to apply a function several times on different inputs. Sometimes the function takes hours to run. I do not want it to last more than 10 seconds. I found the method on a previous post (<a href="http://stackoverflow.com/questions/366682/how-to-limit-execution-time-of-a-function-call-in-python">How to limit execution time of a function call in Python</a>). I can use it but as soon as it's done my kernel dies (unexpectedly). You'll find bellow an example. </p> <p>Does someone face this problem / know why it happens ? </p> <p>Fyk: I use spider (Python 2.7.11 64bits, Qt 4.8.7, PyQt4 (API v2) 4.11.4 on Darwin)</p> <pre><code>import signal import time def signal_handler(signum, frame): raise Exception("Timed out!") for i in range(10): signal.signal(signal.SIGALRM, signal_handler) signal.alarm(10) # Ten seconds try: time.sleep(0.2) # The function I want to apply print("Ok it works") except Exception, msg: print "Timed out!" </code></pre>