MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / run_with_retries

Function run_with_retries

misc/python/materialize/spawn.py:150–160  ·  view source on GitHub ↗

Retry a function until it doesn't raise a `CalledProcessError`, uses exponential backoff until `max_duration` is reached.

(fn: Callable[[], T], max_duration: int = 60)

Source from the content-addressed store, hash-verified

148
149
150def run_with_retries(fn: Callable[[], T], max_duration: int = 60) -> T:
151 """Retry a function until it doesn't raise a `CalledProcessError`, uses
152 exponential backoff until `max_duration` is reached."""
153 for retry in range(math.ceil(math.log2(max_duration))):
154 try:
155 return fn()
156 except subprocess.CalledProcessError as e:
157 sleep_time = 2**retry
158 print(f"Failed: {e}, retrying in {sleep_time}s")
159 time.sleep(sleep_time)
160 return fn()

Callers

nothing calls this directly

Calls 2

fnFunction · 0.85
sleepMethod · 0.45

Tested by

no test coverage detected