retrying
retrying copied to clipboard
The blank except clause is unintuitive
Using a blank except: is unintuitive as it catches KeyBoardInterrupt exceptions too, this means if you try to ctrl+c the code it wont work (unless you do it enough times to hit a limit etc.)
This should be changed to except Exception: which will then catch the vast majority of exceptions that inherit from this. Otherwise you get all exceptions that inherit from BaseException which includes KeyboardInterrupt.
Alternatively it would be useful to add a parameter to retry on specific exceptions (and their subclasses).
@retry(on_exception=requests.exceptions.HTTPError)
@retry(on_exception=socket.timeout)
@retry(on_exception=BaseException)
etc. etc.
The added beifit here is that you state what you want to catch and don't accidentally supress other exceptions.
This change would however be slightly backwards incompatible. The alternative would be to remaind a default to BaseException but allow the user to change this.
It may also be usefull to have a way to give a logger to log exceptions ?
+1 on the logger object
FWIW, I have met my own needs with a small project: http://d0ugal.github.io/retrace/ - I don't have logging support, but that sounds like a good idea.
I am going to unsubscribe from this issue now, but leave it open should it be useful to the project.
Awesome. I'll check it out.