File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import functools
12import importlib
23import importlib .metadata
34import re
5+ import time
46from bisect import bisect_left
57
68import numpy as np
@@ -382,6 +384,25 @@ def check_requirement_version(module_name, version):
382384 return True
383385
384386
387+ def exponential_backoff (max_attempts , base_delay = 1 , max_delay = 60 ):
388+ def decorator (func ):
389+ @functools .wraps (func )
390+ def wrapper (* args , ** kwargs ):
391+ delay = base_delay
392+ for i in range (max_attempts ):
393+ try :
394+ return func (* args , ** kwargs )
395+ except Exception as e :
396+ if i == max_attempts - 1 :
397+ raise e from None
398+ delay = min (delay * 2 , max_delay )
399+ time .sleep (delay )
400+
401+ return wrapper
402+
403+ return decorator
404+
405+
385406def parallel_axis_theorem_from_com (com_inertia_moment , mass , distance ):
386407 """Calculates the moment of inertia of a object relative to a new axis using
387408 the parallel axis theorem. The new axis is parallel to and at a distance
You can’t perform that action at this time.
0 commit comments