Pure python implementation of greenlet API
        Posted  
        
            by Tristan
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Tristan
        
        
        
        Published on 2010-05-30T17:52:59Z
        Indexed on 
            2010/05/30
            20:52 UTC
        
        
        Read the original article
        Hit count: 257
        
python
The greenlet 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.
A simple example:
def test1():
    print 12
    gr2.switch()
    print 34
def test2():
    print 56
    gr1.switch()
    print 78
gr1 = greenlet(test1)
gr2 = greenlet(test2)
gr1.switch()
Should print 12, 56, 34 (and not 78).
© Stack Overflow or respective owner