当前位置: 首页>>代码示例>>Python>>正文


Python inspect.isasyncgenfunction方法代码示例

本文整理汇总了Python中inspect.isasyncgenfunction方法的典型用法代码示例。如果您正苦于以下问题:Python inspect.isasyncgenfunction方法的具体用法?Python inspect.isasyncgenfunction怎么用?Python inspect.isasyncgenfunction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在inspect的用法示例。


在下文中一共展示了inspect.isasyncgenfunction方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: solve_generator

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import isasyncgenfunction [as 别名]
def solve_generator(
    *, call: Callable, stack: AsyncExitStack, sub_values: Dict[str, Any]
) -> Any:
    if is_gen_callable(call):
        cm = contextmanager_in_threadpool(contextmanager(call)(**sub_values))
    elif is_async_gen_callable(call):
        if not inspect.isasyncgenfunction(call):
            # asynccontextmanager from the async_generator backfill pre python3.7
            # does not support callables that are not functions or methods.
            # See https://github.com/python-trio/async_generator/issues/32
            #
            # Expand the callable class into its __call__ method before decorating it.
            # This approach will work on newer python versions as well.
            call = getattr(call, "__call__", None)
        cm = asynccontextmanager(call)(**sub_values)
    return await stack.enter_async_context(cm) 
开发者ID:tiangolo,项目名称:fastapi,代码行数:18,代码来源:utils.py

示例2: _imp

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import isasyncgenfunction [as 别名]
def _imp(cls, loaded):
        """
        Returns the operation implemention from a loaded entrypoint object, or
        None if its not an operation implemention or doesn't have the imp
        parameter which is an operation implemention.
        """
        for obj in [getattr(loaded, "imp", None), loaded]:
            if inspect.isclass(obj) and issubclass(obj, cls):
                return obj
        if (
            inspect.isfunction(loaded)
            or inspect.isgeneratorfunction(loaded)
            or inspect.iscoroutinefunction(loaded)
            or inspect.isasyncgenfunction(loaded)
        ):
            return op(loaded).imp
        return None 
开发者ID:intel,项目名称:dffml,代码行数:19,代码来源:base.py

示例3: protect_with_lock

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import isasyncgenfunction [as 别名]
def protect_with_lock(fn):
    """Use as a decorator to protect an async method with `self._lock`.

    Also works with async gen method so it can be used for `open_cursor`.
    """

    if inspect.isasyncgenfunction(fn):

        @functools.wraps(fn)
        async def wrapper(self, *args, **kwargs):
            async with self._lock:
                async for item in fn.__get__(self)(*args, **kwargs):
                    yield item

    else:
        assert inspect.iscoroutinefunction(fn)

        @functools.wraps(fn)
        async def wrapper(self, *args, **kwargs):
            async with self._lock:
                return await fn.__get__(self)(*args, **kwargs)

    return wrapper 
开发者ID:Scille,项目名称:parsec-cloud,代码行数:25,代码来源:local_database.py

示例4: pytest_collection_modifyitems

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import isasyncgenfunction [as 别名]
def pytest_collection_modifyitems(items):
    """add asyncio marker to all async tests"""
    for item in items:
        if inspect.iscoroutinefunction(item.obj):
            item.add_marker("asyncio")
        if hasattr(inspect, "isasyncgenfunction"):
            # double-check that we aren't mixing yield and async def
            assert not inspect.isasyncgenfunction(item.obj) 
开发者ID:jupyterhub,项目名称:ldapauthenticator,代码行数:10,代码来源:conftest.py

示例5: is_async_gen_callable

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import isasyncgenfunction [as 别名]
def is_async_gen_callable(call: Callable) -> bool:
    if inspect.isasyncgenfunction(call):
        return True
    call = getattr(call, "__call__", None)
    return inspect.isasyncgenfunction(call) 
开发者ID:tiangolo,项目名称:fastapi,代码行数:7,代码来源:utils.py

示例6: add

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import isasyncgenfunction [as 别名]
def add(self, updater):
        assert isinstance(updater, Updater)
        fn = updater.updater
        if six.PY3 and inspect.isasyncgenfunction(fn):
            self.async_loop.call_soon_threadsafe(self._add_async_generator_updater, updater)
        elif six.PY3 and inspect.iscoroutinefunction(fn):
            self.async_loop.call_soon_threadsafe(self._add_async_updater, updater)
        elif inspect.isgeneratorfunction(fn):
            self._add_generator_updater(updater)
        elif callable(fn):
            self._add_callable_updater(updater)
        else:
            raise ValueError('Invalid updater: {}'.format(fn)) 
开发者ID:dankilman,项目名称:awe,代码行数:15,代码来源:element_updater.py

示例7: is_async_function

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import isasyncgenfunction [as 别名]
def is_async_function(func: object) -> bool:
    """Return True if the given function seems to be an async function or async generator"""
    return iscoroutinefunction(func) or (
        sys.version_info >= (3, 6) and inspect.isasyncgenfunction(func)
    ) 
开发者ID:pytest-dev,项目名称:pytest,代码行数:7,代码来源:compat.py

示例8: do_run

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import isasyncgenfunction [as 别名]
def do_run(self):
        async with self:
            if inspect.isasyncgenfunction(self.run):
                return [res async for res in self.run()]
            else:
                return await self.run() 
开发者ID:intel,项目名称:dffml,代码行数:8,代码来源:cmd.py

示例9: decorate_advising_asyncgenerator_py35

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import isasyncgenfunction [as 别名]
def decorate_advising_asyncgenerator_py35(advising_function, cutpoint_function, bind):
    assert isasyncgenfunction(cutpoint_function) or iscoroutinefunction(cutpoint_function)

    async def advising_asyncgenerator_wrapper_py35(*args, **kwargs):
        if bind:
            advisor = advising_function(cutpoint_function, *args, **kwargs)
        else:
            advisor = advising_function(*args, **kwargs)
        if not isgenerator(advisor):
            raise ExpectedGenerator("advising_function %s did not return a generator." % advising_function)
        try:
            advice = next(advisor)
            while True:
                logdebug('Got advice %r from %s', advice, advising_function)
                if advice is Proceed or advice is None or isinstance(advice, Proceed):
                    if isinstance(advice, Proceed):
                        args = advice.args
                        kwargs = advice.kwargs
                    gen = cutpoint_function(*args, **kwargs)
                    try:
                        result = await gen
                    except BaseException:
                        advice = advisor.throw(*sys.exc_info())
                    else:
                        try:
                            advice = advisor.send(result)
                        except StopIteration:
                            return result
                    finally:
                        gen.close()
                elif advice is Return:
                    return
                elif isinstance(advice, Return):
                    return advice.value
                else:
                    raise UnacceptableAdvice("Unknown advice %s" % advice)
        finally:
            advisor.close()
    return mimic(advising_asyncgenerator_wrapper_py35, cutpoint_function) 
开发者ID:ionelmc,项目名称:python-aspectlib,代码行数:41,代码来源:py35support.py

示例10: isasyncfunction

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import isasyncgenfunction [as 别名]
def isasyncfunction(obj):
        if isasyncgenfunction is None:
            return iscoroutinefunction(obj)
        else:
            return isasyncgenfunction(obj) or iscoroutinefunction(obj) 
开发者ID:ionelmc,项目名称:python-aspectlib,代码行数:7,代码来源:__init__.py

示例11: __init__

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import isasyncgenfunction [as 别名]
def __init__(self, func: Callable[..., Any], args, kwargs):
        if not inspect.isasyncgenfunction(func):
            raise RuntimeError('Context manager function must be '
                               'an async-generator')
        self._agen = func(*args, **kwargs)
        self.func = func
        self.args = args
        self.kwargs = kwargs
        self.yield_return = None 
开发者ID:achimnol,项目名称:aiotools,代码行数:11,代码来源:server.py

示例12: __init__

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import isasyncgenfunction [as 别名]
def __init__(self, func: Callable[..., Any], args, kwargs):
            if not inspect.isasyncgenfunction(func):
                raise RuntimeError('Context manager function must be '
                                   'an async-generator')
            self._agen = func(*args, **kwargs)
            self.func = func
            self.args = args
            self.kwargs = kwargs 
开发者ID:achimnol,项目名称:aiotools,代码行数:10,代码来源:context.py

示例13: traverse

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import isasyncgenfunction [as 别名]
def traverse(self, func):
        """
        Traverses an async function or generator, yielding each result.

        This function is private. The class should be used as an iterator instead of using this method.
        """

        if inspect.isasyncgenfunction(func):
            async for send, result in AsyncSender(func(*self.args)):
                send((yield result))
        else:
            yield await func(*self.args) 
开发者ID:Gorialis,项目名称:jishaku,代码行数:14,代码来源:compilation.py

示例14: is_async_generator_fixture

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import isasyncgenfunction [as 别名]
def is_async_generator_fixture(self):
        return inspect.isasyncgenfunction(inspect.unwrap(self.fn)) 
开发者ID:darrenburns,项目名称:ward,代码行数:4,代码来源:fixtures.py

示例15: typed

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import isasyncgenfunction [as 别名]
def typed(obj):
    """Compiles a function or class with cython.

    Use annotations for static type declarations. Example:

        import statically

        @statically.typed
        def add_two(x: int) -> int:
            two: int = 2
            return x + two
    """
    if not _can_cython_inline():
        return obj
    elif has_async_gen_fun and inspect.isasyncgenfunction(obj):
        raise TypeError("Async generator funcions are not supported.")

    source = _get_source_code(obj)
    frame = inspect.currentframe().f_back
    if inspect.isclass(obj):
        locals_ = frame.f_locals
    else:
        locals_ = _get_outer_variables(obj)
    with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        compiled = cython.inline(source, locals=locals_,
                                 globals=frame.f_globals, quiet=True)
        return compiled[obj.__name__] 
开发者ID:AlanCristhian,项目名称:statically,代码行数:30,代码来源:statically.py


注:本文中的inspect.isasyncgenfunction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。