|
37 | 37 | from functools import wraps |
38 | 38 |
|
39 | 39 |
|
40 | | -def retry(ExceptionToCheck, tries=4, delay=3, backoff=2): |
| 40 | +def retry(tries=4, delay=3, backoff=2): |
41 | 41 | """Retry calling the decorated function using an exponential backoff. |
42 | 42 |
|
43 | 43 | http://www.saltycrane.com/blog/2009/11/trying-out-retry-decorator-python/ |
@@ -65,14 +65,11 @@ def f_retry(*args, **kwargs): |
65 | 65 | try: |
66 | 66 | return f(*args, **kwargs) |
67 | 67 | except Exception as e: |
68 | | - if isinstance(e,ExceptionToCheck): |
69 | | - msg = "%s, Retrying in %d seconds..." % (str(e), mdelay) |
70 | | - logging.warning(msg) |
71 | | - time.sleep(mdelay) |
72 | | - mtries -= 1 |
73 | | - mdelay *= backoff |
74 | | - else: |
75 | | - raise e |
| 68 | + msg = "%s, Retrying in %d seconds..." % (str(e), mdelay) |
| 69 | + logging.warning(msg) |
| 70 | + time.sleep(mdelay) |
| 71 | + mtries -= 1 |
| 72 | + mdelay *= backoff |
76 | 73 | return f(*args, **kwargs) |
77 | 74 |
|
78 | 75 | return f_retry # true decorator |
@@ -129,11 +126,12 @@ def log_bug(self, exc:Exception, msg='', report = True, disable_notification = F |
129 | 126 | info = BugReporter.exception(msg, exc, report = self.bug_reporter and report) |
130 | 127 | logging.exception(msg, exc_info=exc) |
131 | 128 | msg = html.escape(msg) |
| 129 | + tb_string = html.escape(info['tb_string']) |
132 | 130 | message = ( |
133 | 131 | '<b>An exception was raised</b>\n' |
134 | | - 'L{line_no}@{file_name}: {exc_type}\n' |
135 | | - f'{msg}\n' |
136 | | - '<pre>{tb_string}</pre>' |
| 132 | + '<i>L{line_no}@{file_name}: {exc_type}<i>\n' |
| 133 | + f'{msg}\n\n' |
| 134 | + f'<pre>{tb_string}</pre>' |
137 | 135 | ).format_map(info) |
138 | 136 |
|
139 | 137 | if len(args): |
@@ -164,7 +162,7 @@ def purge(self, html_str:str, images=True): |
164 | 162 | tag.attrs = dict() |
165 | 163 | return soup |
166 | 164 |
|
167 | | - @retry(HTTPError,10) |
| 165 | + @retry(10) |
168 | 166 | def get_feed(self): |
169 | 167 | with urlopen(self.source) as f: |
170 | 168 | return f.read().decode('utf-8') |
|
0 commit comments