|
1
|
Using signals to timeout a function such as in: http://www.pycs.net/users/0000231/weblog/2004/10/ http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/307871 won't work if the function you are calling overrides the alarm. Using threads gives you away around this.
Apparently cx_Oracle overrides the alarm signal so the signal handling method of timingout a function wasn't working for me. I came up with the threading method as a way around this.
Tags: threads
|
3 comments
Add a comment
Sign in to comment
Download
Copy to clipboard

An improved version supporting exceptions and decorators. Check out http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/483752
Why this doesn't work (!?):
def test(): while True: print "Test" time.sleep(1.5)
if __name__ == '__main__': timeout(test, timeout_duration=3)
Nice, but how do you kill the thread after the timeout?