geowatch.utils.util_retry module

A reimplementation of the retry library [RetryLib] with some minor changes, mainly logging default to a print statement rather than an actual logger.

References

class geowatch.utils.util_retry.DummyLogger[source]

Bases: object

warning(msg, *args)[source]
class geowatch.utils.util_retry.Retry(exceptions=<class 'Exception'>, tries=-1, delay=0, backoff=1, max_delay=None, jitter=0, logger=None)[source]

Bases: object

Reimplementation of the retry internals

geowatch.utils.util_retry.retry_call(f, fargs=None, fkwargs=None, exceptions=<class 'Exception'>, tries=-1, delay=0, max_delay=None, backoff=1, jitter=0, logger=None)[source]

Retry API compatable

CommandLine

xdoctest -m geowatch.utils.util_retry retry_call

Example

>>> from geowatch.utils.util_retry import retry_call
>>> _context = {'attempt': 0}
>>> def f():
>>>     _context['attempt'] += 1
>>>     if _context['attempt'] <= 5:
>>>         raise Exception
>>>     return 1
>>> import pytest
>>> with pytest.raises(Exception):
...     result = retry_call(f, tries=2, delay=0.01)
>>> result = retry_call(f, tries=4, delay=0.01)