MCPcopy Create free account
hub / github.com/apache/arrow / retry

Function retry

python/pyarrow/tests/conftest.py:164–196  ·  view source on GitHub ↗

Retry decorator Parameters ---------- attempts : int, default 3 The number of attempts. delay : float, default 1 Initial delay in seconds. max_delay : float, optional The max delay between attempts. backoff : float, default 1 The multipli

(attempts=3, delay=1.0, max_delay=None, backoff=1)

Source from the content-addressed store, hash-verified

162
163
164def retry(attempts=3, delay=1.0, max_delay=None, backoff=1):
165 """
166 Retry decorator
167
168 Parameters
169 ----------
170 attempts : int, default 3
171 The number of attempts.
172 delay : float, default 1
173 Initial delay in seconds.
174 max_delay : float, optional
175 The max delay between attempts.
176 backoff : float, default 1
177 The multiplier to delay after each attempt.
178 """
179 def decorate(func):
180 @functools.wraps(func)
181 def wrapper(*args, **kwargs):
182 remaining_attempts = attempts
183 curr_delay = delay
184 while remaining_attempts > 0:
185 try:
186 return func(*args, **kwargs)
187 except Exception as err:
188 remaining_attempts -= 1
189 last_exception = err
190 curr_delay *= backoff
191 if max_delay:
192 curr_delay = min(curr_delay, max_delay)
193 time.sleep(curr_delay)
194 raise last_exception
195 return wrapper
196 return decorate
197
198
199@pytest.fixture(scope='session')

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected