1

I'm sure this has been asked before, but I can't find a similar example. I need to be able to call a function with an execution time-limit. If the function takes over this time, then the whole script exits.

This can't be done by timing the whole script! And I only want one, small function to be timed. Is it possible?

For example

    def sleep():
        time.sleep(60)

time("sleep()", limit=30, violation="sys.exit(1)")

Very basic and horrid looking example I know, but it might help the explanation.

joedborg
  • 17,651
  • 32
  • 84
  • 118

1 Answers1

1

Here's a recipe (unix only) http://code.activestate.com/recipes/534115-function-timeout/

user
  • 17,781
  • 20
  • 98
  • 124