I have a function call that will occasionally get stuck. I would like to wrap this function with a decorator that throws an exception if the function call takes more than (say) 60s to complete. How would I do this? I thought about using a separate thread with a counter that would automatically manage a timer. The thread timer should automatically reset after the function completes, as I don't want to keep spawning new threads. How would I do this? Does this already exist in a library? Thanks!
Asked
Active
Viewed 37 times
0
-
2Does this answer your question? [How to limit execution time of a function call in Python](https://stackoverflow.com/questions/366682/how-to-limit-execution-time-of-a-function-call-in-python) also https://stackoverflow.com/questions/492519/timeout-on-a-function-call or even https://stackoverflow.com/questions/43336019/how-to-limit-the-amount-of-time-a-function-can-run-for-add-a-timeout (and many more by Googling `python limit the execution time of a function`) – Tomerikoo Nov 01 '20 at 14:06
-
1https://stackoverflow.com/questions/492519/timeout-on-a-function-call should answer your question – dedoussis Nov 01 '20 at 15:21