【发布时间】:2024-04-22 18:35:01
【问题描述】:
functions in the coroutine table,主要是 create、resume 和 yield 提供了对 Lua 中协程的支持。开发人员将这些协程描述为stackful, first-class and asymmetric。
协程也可以在 Python 中使用,可以使用 enhanced generators(和 yield from),或者在 3.5 版中添加,async and await。
Python 中的协程与 Lua 中的协程相比如何?它们也是堆叠的、一流的和不对称的吗?
为什么 Python 需要这么多的构造(async def、async with、async for、asynchronous comprehensions、...)来构建协程,而 Lua 只能为它们提供三个内置函数?
【问题讨论】:
-
个人猜测为什么 python 需要这么多结构:它是最近才被引入语言的,需要适应现有语法的工作(在其他语句中添加
async)你似乎链接到大量解释各种构造如何工作的资源 - 文档没有回答您的问题吗? -
我不知道 python 协程是如何工作的,但是如果你需要 Lua 协程方面的帮助,我可以 :)
-
Here's 一篇关于 python asyncio 的好帖子,如果有点啰嗦...对于 Lua,我一直认为 Documentation 写得很好
标签: python asynchronous lua async-await coroutine