MCPcopy Create free account
hub / github.com/ZiniuLu/Python-100-Days / Retry

Class Retry

Day66-75/code/main.py:29–48  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27
28
29class Retry(object):
30
31 def __init__(self, *, retry_times=3,
32 wait_secs=5, errors=(Exception, )):
33 self.retry_times = retry_times
34 self.wait_secs = wait_secs
35 self.errors = errors
36
37 def __call__(self, fn):
38
39 def wrapper(*args, **kwargs):
40 for _ in range(self.retry_times):
41 try:
42 return fn(*args, **kwargs)
43 except self.errors as e:
44 print(e)
45 sleep((random() + 1) * self.wait_secs)
46 return None
47
48 return wrapper
49
50
51class Spider(object):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected