(fun, fargs=(), max_tries=5, sleep_duration=5.0, sleep_factor=2.0)
| 82 | # Try and retry with exponential backoff if an exception is raised |
| 83 | # pylint: disable-next=inconsistent-return-statements |
| 84 | def 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 | |
| 103 | def clone_cppcheck(repo_path, migrate_from_path): |
no test coverage detected