Timeout on a function call

后端 未结 18 1489
挽巷
挽巷 2020-11-21 04:53

I\'m calling a function in Python which I know may stall and force me to restart the script.

How do I call the function or what do I wrap it in so that if it takes

18条回答
  •  不知归路
    2020-11-21 05:19

    The stopit package, found on pypi, seems to handle timeouts well.

    I like the @stopit.threading_timeoutable decorator, which adds a timeout parameter to the decorated function, which does what you expect, it stops the function.

    Check it out on pypi: https://pypi.python.org/pypi/stopit

提交回复
热议问题