MCPcopy
hub / github.com/omkarcloud/botasaurus / wrapper

Function wrapper

botasaurus/decorator_helpers.py:78–111  ·  view source on GitHub ↗
(*args, **kwargs)

Source from the content-addressed store, hash-verified

76 def decorator(func):
77 @wraps(func)
78 def wrapper(*args, **kwargs):
79 tries = 0
80
81 while tries < retries:
82 tries += 1
83 try:
84 created_result = func(*args, **kwargs)
85 return created_result
86 except Exception as e:
87 if instances != ANY:
88 errors_only_instances = list(map(lambda el: el[0] if isinstance(el, tuple) else el, instances)) if instances else []
89 if instances != ANY:
90 is_valid_error, index = is_errors_instance(errors_only_instances, e)
91
92 if not is_valid_error:
93 raise e
94
95 if raise_exception:
96 traceback.print_exc()
97
98 if instances != ANY:
99 if instances and isinstance(instances[index], tuple):
100 instances[index][1]()
101
102 if tries == retries:
103 if on_failed_after_retry_exhausted is not None:
104 on_failed_after_retry_exhausted(e)
105 if raise_exception:
106 raise e
107
108 print('Retrying')
109
110 if wait_time is not None:
111 sleep(wait_time)
112 return wrapper
113 return decorator
114

Callers

nothing calls this directly

Calls 3

is_errors_instanceFunction · 0.70
sleepFunction · 0.50

Tested by

no test coverage detected