本文介绍了这两种基于生成器的协程是否具有相同的概念?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎有两种基于生成器的协程:

There seem to be two kinds of generator-based coroutine:


  1. 来自


  • 来自Python的果壳,没有明确地将其称为
    基于发电机的协程:

  • From Python in a Nutshell, which doesn't explicitly call it"generator-based coroutine":

    当您基于 asyncio 编写Python代码时(最好也使用asyncio.org的
    附加模块),通常会编写
    协程函数。直到包含Python 3.4,此类函数
    都是生成器,使用第95页的 $ yield
    from(v3-only)中包含的 yield from 语句,用 @ asyncio.coroutine 装饰,在$ 518上的 asyncio协程中覆盖了

    来自


    也称其为基于发电机的协程。

    http://masnun.com/2015/11/13/python-generators-coroutines-native-coroutines-and-async-await.htmlalso calls it "generator-based coroutine".

    是两种基于指令的协同程序是否具有相同的概念?

    Are the two kinds of generator-based coroutines the same concept?

    如果不是,它们在用途和用法上有什么区别?

    If not, what are their differences in purposes and usages?

    谢谢。

    推荐答案

    它们是同一种协程。 types.coroutine asyncio.coroutine 只是创建它们的两种单独方法。

    They're the same kind of coroutine. types.coroutine and asyncio.coroutine are just two separate ways to create them.

    asyncio.coroutine 较旧,早于 async 协程的引入,其功能具有现在已经存在 async 协程。

    asyncio.coroutine is older, predating the introduction of async coroutines, and its functionality has shifted somewhat from its original behavior now that async coroutines exist.

    asyncio.coroutine types.coroutine 的行为略有不同,尤其是应用于生成器函数以外的任何东西,或者asyncio位于。

    asyncio.coroutine and types.coroutine have subtly different behavior, especially if applied to anything other than a generator function, or if asyncio is in debug mode.

    这篇关于这两种基于生成器的协程是否具有相同的概念?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

  • 10-26 23:46