开发者

Python kill hanging function

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! A开发者_JAVA百科nd 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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜