MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / try_retry

Function try_retry

tools/donate_cpu_lib.py:84–100  ·  view source on GitHub ↗
(fun, fargs=(), max_tries=5, sleep_duration=5.0, sleep_factor=2.0)

Source from the content-addressed store, hash-verified

82# Try and retry with exponential backoff if an exception is raised
83# pylint: disable-next=inconsistent-return-statements
84def try_retry(fun, fargs=(), max_tries=5, sleep_duration=5.0, sleep_factor=2.0):
85 for i in range(max_tries):
86 try:
87 return fun(*fargs)
88 except KeyboardInterrupt as e:
89 # Do not retry in case of user abort
90 raise e
91 except BaseException as e:
92 if i < max_tries - 1:
93 print("{} in {}: {}".format(type(e).__name__, fun.__name__, str(e)))
94 print("Trying {} again in {} seconds".format(fun.__name__, sleep_duration))
95 time.sleep(sleep_duration)
96 sleep_duration *= sleep_factor
97 # do not return - re-try
98 else:
99 print("Maximum number of tries reached for {}".format(fun.__name__))
100 raise e
101
102
103def clone_cppcheck(repo_path, migrate_from_path):

Callers 6

get_packages_countFunction · 0.85
get_packageFunction · 0.85
__remove_treeFunction · 0.85
upload_resultsFunction · 0.85
upload_infoFunction · 0.85
upload_nodataFunction · 0.85

Calls 3

strFunction · 0.85
formatMethod · 0.80
typeFunction · 0.50

Tested by

no test coverage detected