Bases: object
Helper to make function return an exception, rather than raise it.
Because every exception that is unhandled by greenlet will be logged, it is desirable to prevent non-error exceptions from leaving a greenlet. This can done with simple try/except construct:
def wrapped_func(*args, **kwargs):
try:
return func(*args, **kwargs)
except (A, B, C) as ex:
return ex
wrap_errors provides a shortcut to write that in one line:
wrapped_func = wrap_errors((A, B, C), func)
It also preserves __str__ and __repr__ of the original function.
Make a new function from `func’, such that it catches `errors’ (an Exception subclass, or a tuple of Exception subclasses) and return it as a value.
Next page: What’s new in gevent 1.0