Re: decorators and alarms

2015-05-22 Thread Paul Rubin
Jason Friedman writes: > Found an answer: > https://wiki.python.org/moin/PythonDecoratorLibrary#Function_Timeout That is pretty limited since signal handlers always run in the main thread, and that wrapper takes over the sigalarm handler which some other part of the program might also want to use

Re: decorators and alarms

2015-05-22 Thread Jason Friedman
> But, I'd like to expand this to take some generic code, not just a > shell command, and terminate it if it does not return quickly. > > @time_limiter > def generic_function(arg1, arg2, time_limit=10): > do_some_stuff() > do_some_other_stuff() > return val1, val2 > > If generic_functio

decorators and alarms

2015-05-22 Thread Jason Friedman
I have the following code to run a shell command and kill it if it does not return within a certain amount of time: def run_with_time_limit(command, limit): """Run the given command via a shell. Kill the command, and raise an exception, if the execution time exceeds seconds. Else