pnpnpn / timeout-decorator

Timeout decorator for Python
MIT License
620 stars 96 forks source link

feature request: timeout_exception=None to terminate function without raising exception #70

Open mdavis-xyz opened 2 years ago

mdavis-xyz commented 2 years ago

I have some code where I save some non-essential logging information to AWS CloudWatch. Often it takes too long, so I use this timeout decorator. But if it does time out, I don't want my whole script to fail. I want to ignore the timeout error and continue. Currently I need to wrap the code that invokes my decorated function in a try/except block. I would like to be able to tell the decorator to not raise any exception when the function times out. Just stop the function, and then return None.

timeout_exception=None would be one possible way to do this. Or perhaps a new argument?