执行注册的函数或者实例的方法.

        如果函数或者方法是协程则执行协程,如果是函数则使用执行器执行,默认使用的是多进程.

        Parameters:
            ID (str): 任务的ID
            method (str): 任务调用的函数名
            args (Any): 位置参数
            kwargs (Any): 关键字参数

        Raise:
            (RPCRuntimeError): - 当执行调用后抛出了异常,那就算做RPC运行时异常

        Return:
            (Any): - 被调用函数的返回

async def apply(self, ID: str, method: str, *args: Any, **kwargs: Any):
        """执行注册的函数或者实例的方法.

        如果函数或者方法是协程则执行协程,如果是函数则使用执行器执行,默认使用的是多进程.

        Parameters:
            ID (str): 任务的ID
            method (str): 任务调用的函数名
            args (Any): 位置参数
            kwargs (Any): 关键字参数

        Raise:
            (RPCRuntimeError): - 当执行调用后抛出了异常,那就算做RPC运行时异常

        Return:
            (Any): - 被调用函数的返回

        """
        func = None
        try:
            # check to see if a matching function has been registered
            func = self.funcs[method]
        except KeyError:
            if self.instance is not None:
                # check for a _dispatch method
                try:
                    func = resolve_dotted_attribute(
                        self.instance,
                        method,
                        self.allow_dotted_names)
                except AttributeError:
                    pass
        if func is not None:
            sig = inspect.signature(func)
            try:
                sig.bind(*args, **kwargs)
            except:
                raise ParamError(
                    "args can not bind to method {}".format(method), ID)
            if method.startswith("system."):
                try:
                    result = func(*args, **kwargs)
                except Exception as e:
                    raise RPCRuntimeError(
                        'Error:{} happend in method {}'.format(
                            e.__class__.__name__,
                            method
                        ),
                        ID
                    )
                else:
                    return result
            if inspect.iscoroutinefunction(func):
                try:
                    result = await func(*args, **kwargs)
                except Exception as e:
                    raise RPCRuntimeError(
                        'Error:{} happend in method {}'.format(
                            e.__class__.__name__,
                            method
                        ),
                        ID
                    )
                else:
                    return result
            elif inspect.isasyncgenfunction(func):
                result = func(*args, **kwargs)
                return result
            elif inspect.isfunction(func) or inspect.ismethod(func):
                try:
                    f = partial(func, *args, **kwargs)
                    result = await self.loop.run_in_executor(None, f)
                except Exception as e:
                    raise RPCRuntimeError(
                        'Error:{} happend in method {}'.format(
                            e.__class__.__name__,
                            method
                        ),
                        ID
                    )
                else:
                    return result
            else:
                raise RpcException('method "%s" is not supported' % method)
        else:
            raise NotFindError('method "%s" is not supported' % method, ID)