def ensure_method args kwargs delay while True try return api method a

1
2
3
4
5
6
7
8
9
def ensure_method(*args, **kwargs):
delay = 1
while True:
try:
return api.method(*args, **kwargs)
except requests.ConnectionError:
logging.getLogger(__name__).warning('Connection error, sleeping for %d sec' % delay)
time.sleep(delay)
delay *= 2