def time_aspect2(cutpoint, *args, **kwargs): result = yield Proceed(*args, **kwargs) if cutpoint.__name__.startswith( '_n_'): # call the actual function with all parameters if result == None: raise ValueError('None type computed') yield Return(result) # return the result
def memoize_aspect(f, *args, **kwargs): key = f.__name__ + "|" + str(args) + "|" + str(kwargs) # print('LOOK AT ME', inspect.getsource(f)) if(not key in memo): memo[key] = yield Proceed(*args, **kwargs) yield Return(memo[key]) else: yield Return(memo[key])
def null_aspect(f, *args, **kwargs): result = yield Proceed(*args, **kwargs) if f.__name__.startswith('_n_'): if result is None: raise ValueError('null-safe function returned None!') yield Return(result)
def memoize_aspect(cutpoint, *args, **kwargs): if (str(cutpoint.__name__) + str(args)) not in cache: cache[str(cutpoint.__name__) + str(args)] = yield Proceed( *args, **kwargs) # call the actual function with all parameters return cache[str(cutpoint.__name__) + str(args)]
def a1(*args, **kwargs): g = 100 print("msg1") x = yield Proceed(*args, **kwargs) print("msg2") yield Return(x + g)
def a2(*args, **kwargs): print("msg1") x = yield Proceed(*args, **kwargs) yield Return(x)