def capture_exceptions(async_result):
 def capture(function):
  @functools.wraps(function)
  def captured_function(*args, **kwargs):
   try:
    return function(*args, **kwargs)
   except Exception as exc:
    async_result.set_exception(exc)
  return captured_function
 return capture

def capture_exceptions ( async_result ) : def capture ( function ) : @ functools . wraps ( function ) def captured_function ( * args , ** kwargs ) : try : return function ( * args , ** kwargs ) except Exception as exc : async_result . set_exception ( exc ) return captured_function return capture
return a new decorated function that propagates the exceptions of the wrapped function to an async_result .