3 ms·
Node.js users interested in seeing how generators interact with their async system should probably look at the Python Twisted library, which has had years to re
by jerf 13y ago
Node.js users interested in seeing how generators interact with their async system should probably look at the Python Twisted library, which has had years to refine that pattern.
- aeflash 13y agoAre generators allowed in RPython/PyPy yet? Last I checked, they were disallowed due to the difficulties of making them performant.
- schmichael 13y agoPyPy absolutely supports generators. Python's stdlib uses them extensively. If you were worrying about the JIT not supporting them, it appears to just fine: gentest.py: def gen(): for i in xrange(10**9): yield i for i in gen(): pass $ time python gentest.py # python 2.7 real 1m12.956s user 1m12.736s sys 0m0.000s $ time pypy gentest.py # pypy 2.0.2 real 0m5.728s user 0m5.708s sys 0m0.000s
- masklinn 13y agoCan also check out tulip[0] which attempts to be a standardization of sort to give a common core interface to various event loop libraries, and defines a full event loop and adds coroutines on top[1]. Since it's a tentative distillation of existing systems and has an extensive design document, it might be simpler than diving into Twisted. [0] http://www.python.org/dev/peps/pep-3156/ http://www.python.org/dev/peps/pep-3156/ [1] http://www.python.org/dev/peps/pep-3156/#coroutines-and-the-scheduler http://www.python.org/dev/peps/pep-3156/#coroutines-and-the-...