Esempio n. 1
0
        def inner(*args, **kwargs):
            start = time.time()
            from file_cache.utils.other import is_mini_args
            args_mini = [item  if is_mini_args(item) else ex_type_name(item) for item in args  ]

            kwargs_mini = [ (k, v ) if is_mini_args(v) else (k, ex_type_name(v)) for k, v in kwargs.items()]
            arg_count = len(args) + len(kwargs)
            if paras:
                log(replace_useless_mark("FN#%s begin with(%s paras) :%s, %s" % (fn.__name__, arg_count, args_mini, kwargs_mini)))
            else:
                log(f"{fn.__name__} begin with {arg_count} paras")
            try:
                result = fn(*args, **kwargs)
            except Exception as e:
                logger.exception(e)
                logger.error(f'Exception from: FN#{fn.__name__}({args_mini}, {kwargs_mini}), end with:{type(e)}')

                raise e
            duration = time.time() - start
            if duration < 60:
                duration = f'{duration:04.1f} sec'
            else:
                duration = f'{duration/60.0:04.1f} min'
            log(replace_useless_mark(f'<<cost {duration}>>:FN#{fn.__name__}({args_mini}, {kwargs_mini}), return:{summary_result(result)}, end '))


            #logger.log(level, format, repr(fn), duration * 1000)
            return result
Esempio n. 2
0
def is_support_cache(*args, **kwargs):
    for arg in args:
        if not is_mini_args(arg) and arg is not None:
            logger.debug(f'There is {type(arg).__name__} in the args')
            return False
    for _, arg in kwargs.items():
        if not is_mini_args(arg) and arg is not None:
            logger.debug(f'There is {type(arg).__name__} in the kwargs')
            return False
    return True
Esempio n. 3
0
def get_pretty_info(args):
    if isinstance(args,(list, tuple)) and len(args)>0:
        mini =  [str(item) if is_mini_args(item) else type(item).__name__ for item in args]
        return replace_useless_mark(','.join(mini))
    elif isinstance(args, (dict)) and len(args)>0:
        mini = [f'{k}={v}' if is_mini_args(v) else f'{k}={type(v).__name__}' for k, v in args.items()]
        return replace_useless_mark(','.join(mini))
    elif '__len__' in dir(args) and len(args)==0:
        return ''
    elif isinstance(args, (str, float, int)):
        return args
    elif args is None:
        return 'None'
    else:
        return replace_useless_mark(type(args).__name__)