Call the function with the args/kwds and tell the ApplyResult
        that its result is ready. Correctly handles the exceptions
        happening during the execution of the function
763754
def process(self):
        
        try:
            result = self._func(*self._args, **self._kwds)
        except:
            self._result._set_exception()
        else:
            self._result._set_value(result)
713747
def raises(self, exception_type, function, *args, **kwargs):
        
        try:
            result = function(*args, **kwargs)
            self.log_error("{} did not throw exception {}".format(
                function.__name__,
                exception_type.__name__
            ), None)
            return result
        except Exception as e:
            if type(e) != exception_type:
                self.log_error("{} did raise {}: {}".format(
                    function.__name__,
                    type(e).__name__, e
                ), None)
1152705
def handle_exception(logger, **kw_decorator):
    

    def decorator(query_func):
        @functools.wraps(query_func)
        def wrapper(*args, **kwargs):
            try:
                return query_func(*args, **kwargs)
            except Exception as e:
                logger.info('Exception in function {0} -- {1}'.format(query_func.__name__, e))
                if valid_dict(kw_decorator, ['subject', 'sender', 'username', 'password', 'host', 'receiver']):
                    logger.info('Now is sending the email with exception message')
                    t = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
                    msg = t + ' ' + 'Exception in function {0} -- {1}'.format(query_func.__name__, e)
                    _send(subject=kw_decorator['subject'],
                          text=msg,
                          sender=kw_decorator['sender'],
                          username=kw_decorator['username'],
                          password=kw_decorator['password'],
                          host=kw_decorator['host'],
                          receiver=kw_decorator['receiver'])

                    logger.info('Email is sent')

        return wrapper

    return decorator
291465
def call(func, args):
    
    assert hasattr(func, '__call__'), 'Cannot call func: {}'.format(
        func.__name__)
    raw_func = (
        func if isinstance(func, FunctionType) else func.__class__.__call__)
    hints = collections.defaultdict(lambda: Any, get_type_hints(raw_func))
    argspec = _getargspec(raw_func)
    named_args = {}
    varargs = ()
    for k, nk, v in _normalize(args):
        if nk == argspec.varargs:
            hints[nk] = Tuple[hints[nk], ...]
        elif nk not in argspec.args and argspec.varkw in hints:
            hints[nk] = hints[argspec.varkw]
        try:
            value = cast(hints[nk], v)
        except TypeError as e:
            _LOGGER.exception(e)
            six.raise_from(exc.InvalidCliValueError(k, v), e)
        if nk == argspec.varargs:
            varargs = value
        elif (nk in argspec.args or argspec.varkw) and (
                nk not in named_args or named_args[nk] is None):
            named_args[nk] = value
    return func(*varargs, **named_args)
533650
def RaiseIfNotErrorSuccess(result, func = None, arguments = ()):
    
    if result != ERROR_SUCCESS:
        raise ctypes.WinError(result)
    return result
434909
def _run_callback(
        self, callback: Callable, *args: Any, **kwargs: Any
    ) -> "Optional[Future[Any]]":
        
        try:
            result = callback(*args, **kwargs)
        except Exception:
            self.handler.log_exception(*sys.exc_info())
            self._abort()
            return None
        else:
            if result is not None:
                result = gen.convert_yielded(result)
                assert self.stream is not None
                self.stream.io_loop.add_future(result, lambda f: f.result())
            return result
538356
def on_finish(func, handler, args, kwargs):
    
    tracing = handler.settings.get('opentracing_tracing')
    tracing._finish_tracing(handler)

    return func(*args, **kwargs)
268343
def submit(self, method, method_args=(), method_kwargs={}, done_callback=None, done_kwargs={}, loop=None):
        '''
        
        '''
        _future = self.pool.submit(method, *method_args, **method_kwargs)
        self.current_id += 1
        if done_callback:
            _future.add_done_callback(lambda _f:done_callback(_f,loop,**done_kwargs))#done kwargs, hardcoded kwargs
        self.request_pool[self.current_id] = _future
        return self.current_id, _future
1017574
def execute(function, name):
    
    try:
        return TaskResult(name, True, None, function())
    except Exception as exc:
        return TaskResult(name, False, exc, None)
528021
def _setResult(self, result):
        
        if self._result is not _NO_RESULT:
            raise AlreadyCalledError()

        self._result = result
1004519
def invoke(self):
        

        # Don't sleep a hook if it has never run
        if self.timeout_milliseconds > 0:
            self.ready_time = (
                datetime.now() +
                timedelta(milliseconds=self.timeout_milliseconds))

        self.callback(self.callback_args)
1188742
def _sync_call(self, func):
        

        @functools.wraps(func)
        def wrapper(*args, **kwargs):
            if self._start_msg:
                self._start_print()
            result = func(*args, **kwargs)
            if self._end_msg:
                print(self._end_msg)
            return result

        setattr(wrapper, ANNOTATED, True)
        return wrapper
535373
def call_func(self, *args, **kwargs):
        """"""
        asyncio.gather(
            self.cron(*args, **kwargs),
            loop=self.loop, return_exceptions=True
            ).add_done_callback(self.set_result)
1363272
def add_to_apply_calls(self, func, **kwargs):
        
        import dask

        self.delayed_call = dask.delayed(func)(self.delayed_call, **kwargs)
        return self
478384
def prepare(cls, *args, **kwargs):
        
        cls.args = args
        cls.kwargs = kwargs
        cls.prepared = True
440092
def callback(func):
    
    @functools.wraps(func)
    def wrapped(*args, **kwargs):
        result = func(*args, **kwargs)
        if inspect.iscoroutine(result):
            aio_loop.create_task(result)

    return wrapped
1195193
def callback(self, callback, *args, **kwds):
        
        return self << _CloseDummy(callback, args, kwds)