Naive Retrying

Learn about naive retrying in Python.

There’s a common pattern that can be seen across all sorts of programs that can be summarized with the word “retrying”. It is directly tied to the idea of trying something again that returned an error or raised an exception when it was not expected.

Basic retrying pattern

The basic pattern that most developers implement looks like what is shown in the following example.

Press + to interact
while True:
try:
do_something()
except:
pass
else:
break

The above example does not provide any down time for the called function. Usually, smarter strategies are implemented. ...