title: Pure python implementation of greenlet API
body: <p>The <a href="http://codespeak.net/py/0.9.2/greenlet.html" rel="noreferrer">greenlet</a> package is used by gevent and eventlet for asynchronous IO.  It is written as a C-extension and therefore doesn't work with Jython or IronPython.  If performance is of no concern, what is the easiest approach to implementing the greenlet API in pure Python.</p>
  
  <p>A simple example:</p>
  
  <pre><code>def test1():
      print 12
      gr2.switch()
      print 34
  
  def test2():
      print 56
      gr1.switch()
      print 78
  
  gr1 = greenlet(test1)
  gr2 = greenlet(test2)
  gr1.switch()
  </code></pre>
  
  <p>Should print 12, 56, 34 (and not 78).</p>