mirror of
https://github.com/Garmelon/PFERD.git
synced 2026-04-13 07:55:05 +02:00
Retry on more I/O Errors
This commit is contained in:
parent
14cdfb6a69
commit
1f2af3a290
3 changed files with 31 additions and 14 deletions
|
|
@ -37,3 +37,21 @@ def swallow_and_print_errors(function: TFun) -> TFun:
|
|||
Console().print_exception()
|
||||
return None
|
||||
return cast(TFun, inner)
|
||||
|
||||
|
||||
def retry_on_io_exception(max_retries: int, message: str) -> Callable[[TFun], TFun]:
|
||||
"""
|
||||
Decorates a function and retries it on any exception until the max retries count is hit.
|
||||
"""
|
||||
def retry(function: TFun) -> TFun:
|
||||
def inner(*args: Any, **kwargs: Any) -> Any:
|
||||
for i in range(0, max_retries):
|
||||
# pylint: disable=broad-except
|
||||
try:
|
||||
return function(*args, **kwargs)
|
||||
except IOError as error:
|
||||
PRETTY.warning(f"Error duing operation '{message}': {error}")
|
||||
PRETTY.warning(
|
||||
f"Retrying operation '{message}'. Remaining retries: {max_retries - 1 - i}")
|
||||
return cast(TFun, inner)
|
||||
return retry
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue