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
> 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
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