asyncsupport.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:ieee-cs-txst 作者: codestar12 项目源码 文件源码
def make_async_loop_context(iterable, recurse=None, depth0=0):
    # Length is more complicated and less efficient in async mode.  The
    # reason for this is that we cannot know if length will be used
    # upfront but because length is a property we cannot lazily execute it
    # later.  This means that we need to buffer it up and measure :(
    #
    # We however only do this for actual iterators, not for async
    # iterators as blocking here does not seem like the best idea in the
    # world.
    try:
        length = len(iterable)
    except (TypeError, AttributeError):
        if not hasattr(iterable, '__aiter__'):
            iterable = tuple(iterable)
            length = len(iterable)
        else:
            length = None
    async_iterator = auto_aiter(iterable)
    try:
        after = await async_iterator.__anext__()
    except StopAsyncIteration:
        after = _last_iteration
    return AsyncLoopContext(async_iterator, after, length, recurse, depth0)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号