How do coroutines in Python compare to those in Lua?
<p>Support for coroutines in Lua is provided by <a href="https://www.lua.org/manual/5.3/manual.html#2.6">functions in the <code>coroutine</code> table</a>, primarily <code>create</code>, <code>resume</code> and <code>yield</code>. The developers describe these coroutines as <a href="http://laser.inf.ethz.ch/2012/slides/Ierusalimschy/coroutines-4.pdf">stackful, first-class and asymmetric</a>.</p>

<p>Coroutines are also available in Python, either using <a href="https://www.python.org/dev/peps/pep-0342/">enhanced generators</a> (and <a href="https://www.python.org/dev/peps/pep-0380/"><code>yield from</code></a>) or, added in version 3.5, <a href="https://www.python.org/dev/peps/pep-0492/"><code>async</code> and <code>await</code></a>.</p>

<p>How do coroutines in Python compare to those in Lua? Are they also stackful, first-class and asymmetric?</p>

<p>Why does Python require so many constructs (<code>async def</code>, <code>async with</code>, <code>async for</code>, <a href="https://www.python.org/dev/peps/pep-0530/">asynchronous comprehensions</a>, ...) for coroutines, while Lua can provide them with just three built-in functions?</p>

<p>The simple answer is that they are different languages.  Yes, Python coroutines are stackful, first-class and asymmetric.  See this answer: <a href="http://stackoverflow.com/q/715758/584846">Coroutine vs Continuation vs Generator</a></p>

<p>From the Lua <a href="https://www.lua.org/pil/9.1.html" rel="nofollow">documentation</a>:</p>

<blockquote>
  <p>Some people call asymmetric coroutine semi-coroutines (because they
  are not symmetrical, they are not really co). However, other people
  use the same term semi-coroutine to denote a restricted implementation
  of coroutines, where a coroutine can only suspend its execution when
  it is not inside any auxiliary function, that is, when it has no
  pending calls in its control stack. In other words, only the main body
  of such semi-coroutines can yield. A generator in Python is an example
  of this meaning of semi-coroutines.</p>
  
  <p>Unlike the difference between symmetric and asymmetric coroutines, the
  difference between coroutines and generators (as presented in Python)
  is a deep one; generators are simply not powerful enough to implement
  several interesting constructions that we can write with true
  coroutines. Lua offers true, asymmetric coroutines. Those that prefer
  symmetric coroutines can implement them on top of the asymmetric
  facilities of Lua. It is an easy task. (Basically, each transfer does
  a yield followed by a resume.)</p>
</blockquote>

<p>Also, see this discussion on Python's developer mail list: <a href="https://mail.python.org/pipermail/python-dev/2015-April/139695.html" rel="nofollow">PEP 492: What is the real goal?</a></p>

python asynchronous lua async-await coroutine