MCPcopy
hub / github.com/rholder/retrying / Attempt

Class Attempt

retrying.py:225–255  ·  view source on GitHub ↗

An Attempt encapsulates a call to a target function that may end as a normal return value from the function or an Exception depending on what occurred during the execution.

Source from the content-addressed store, hash-verified

223
224
225class Attempt(object):
226 """
227 An Attempt encapsulates a call to a target function that may end as a
228 normal return value from the function or an Exception depending on what
229 occurred during the execution.
230 """
231
232 def __init__(self, value, attempt_number, has_exception):
233 self.value = value
234 self.attempt_number = attempt_number
235 self.has_exception = has_exception
236
237 def get(self, wrap_exception=False):
238 """
239 Return the return value of this Attempt instance or raise an Exception.
240 If wrap_exception is true, this Attempt is wrapped inside of a
241 RetryError before being raised.
242 """
243 if self.has_exception:
244 if wrap_exception:
245 raise RetryError(self)
246 else:
247 six.reraise(self.value[0], self.value[1], self.value[2])
248 else:
249 return self.value
250
251 def __repr__(self):
252 if self.has_exception:
253 return "Attempts: {0}, Error:\n{1}".format(self.attempt_number, "".join(traceback.format_tb(self.value[2])))
254 else:
255 return "Attempts: {0}, Value: {1}".format(self.attempt_number, self.value)
256
257
258class RetryError(Exception):

Callers 1

callMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…