From 952c880d10e668997db0833e46543e7bcb93bc19 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Thu, 17 Mar 2016 19:14:02 +0100 Subject: [PATCH] callback could raises (not only returns) --- tiramisu/autolib.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tiramisu/autolib.py b/tiramisu/autolib.py index 54d165b..082afb0 100644 --- a/tiramisu/autolib.py +++ b/tiramisu/autolib.py @@ -211,7 +211,7 @@ def carry_out_calculation(option, context, callback, callback_params, args.append(val) else: kwargs[key] = val - return calculate(callback, args, kwargs) + return calculate(callback, args, kwargs, returns_raise) else: # no value is multi # return a single value @@ -224,7 +224,7 @@ def carry_out_calculation(option, context, callback, callback_params, args.append(couple[0]) else: kwargs[key] = couple[0] - ret = calculate(callback, args, kwargs) + ret = calculate(callback, args, kwargs, returns_raise) if not option.impl_is_optiondescription() and callback_params != {} and isinstance(ret, list) and \ option.impl_is_master_slaves('slave'): raise SlaveError(_("callback cannot return a list for a " @@ -232,7 +232,7 @@ def carry_out_calculation(option, context, callback, callback_params, return ret -def calculate(callback, args, kwargs): +def calculate(callback, args, kwargs, returns_raise): """wrapper that launches the 'callback' :param callback: callback function @@ -240,4 +240,10 @@ def calculate(callback, args, kwargs): :param kwargs: in the callback's arity, the named parameters """ - return callback(*args, **kwargs) + if returns_raise: + try: + return callback(*args, **kwargs) + except ValueError, err: + return err + else: + return callback(*args, **kwargs)