Skip to content

Instantly share code, notes, and snippets.

@echohack
Last active December 14, 2015 05:39
Show Gist options
  • Save echohack/5036807 to your computer and use it in GitHub Desktop.
Save echohack/5036807 to your computer and use it in GitHub Desktop.
import socket
# ...snippet
class ExceededRetries(StopIteration):
pass
def call_api(url):
try:
requests.get(url="url")
except:
socket.error as e:
print("Could not open socket: {0}".format(e)
def retry(number_retries, function, *args):
for item in range(number_retries):
result = function(*args)
if result:
return result
if ((item == (number_retries - 1)) and (not result)):
raise ExceededRetries("Failed to call {0} within {1} retries.".format(function, number_retries))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment