Possible Duplicate:
Timeout on a Python function call
I want to implement that when the function took more than 90 seconds to complete it should return immediately when timeout. Is there any way to achieve that?
def abc(string): import re if re.match('some_pattern', string): return True else: return False abc('some string to match') Edited
Please download this test file. I have created a thread class and raise an exception within thread if timeout error occur. But thread is still alive because it prints i am still alive :) even after exception. Why an exception does not force the thread to stop??
signal.alarm(),signal.setitmer()etc. Be careful with those answers -- they probably rely on Python exceptions being thrown, but I doubt a Python exception can interruptre.match(). (Not sure about the right answer. Maybe use a subprocess, and kill it after 90 seconds.)