Esempio n. 1
0
 def wrapper(*args, **kwargs):
     trigger_time = time.time()
     try:
         rv = func(*args, **kwargs)
     except Return as e:
         metric.labels(*labels).observe(time.time() - trigger_time)
         raise e
     return rv
Esempio n. 2
0
def accumulate(iterable, func=operator.add):
    """
    Iterate over running totals, ie [a,b,c,d] -> func( func( func(a, b), c), d) with each func result yielded.
    Func is operator.add by default.

    >>> list(accumulate([1,2,3,4,5]))
    [1, 3, 6, 10, 15]
    >>> list(accumulate([1,2,3,4,5], operator.mul))
    [1, 2, 6, 24, 120]

    :param iterable: Iterable
    :param func: method (default=operator.add) to call for each pair of (last call result or first item, next item)
    :return generator: Generator
    """
    it = iter(iterable)
    try:
        total = next(it)
    except StopIteration:
        return
    yield total
    for element in it:
        total = func(total, element)
        yield total
Esempio n. 3
0
 def wrapper(*args, **kwargs):
     trigger_time = time.time()
     rv = func(*args, **kwargs)
     metric.labels(*labels).observe(time.time() - trigger_time)
     return rv
Esempio n. 4
0
 def wrapper(self, *args, **kwargs):
     if self.executor_config.get("DEBUG", False):
         logger.debug("Executor %s DEBUG set, not calling 'stop_builder()'", self.name)
         return
     return func(self, *args, **kwargs)
Esempio n. 5
0
 def _thread_safe_func(*args, **kwargs):
     key = cachetools.keys.hashkey(*args, **kwargs)
     with lock_dict[key]:
         return func(*args, **kwargs)