goless is now available on the Python Package Index: https://pypi.python.org/pypi/goless . You can do
pip install goless and get Go-like primitives to use in Python, that runs atop gevent, PyPy, or Stackless Python. You can write code like:
channel = goless.chan() def goroutine(): while True: value = channel.recv() channel.send(value ** 2) goless.go(goroutine) for i in xrange(2, 5): channel.send(i) squared = channel.recv() print('%s squared is %s' % (i, squared)) # Output: # 2 squared is 4 # 3 squared is 9 # 4 squared is 16
I’ve also ported the goless benchmarks to Go, for some basic comparisons to using goless on various Python runtimes (PyPy, CPython) and backends (gevent, stackless): https://goless.readthedocs.org/en/latest/#a-benchmarks
Thanks to Rui Carmo we have more extensive examples of how to use goless (but if you’ve done or read any Go, it should be relatively straightforward). Check them out in the examples folder: https://github.com/rgalanakis/goless/tree/master/examples
And just a compatibility note (which is covered in the docs, and explained in the exception you get if you try to use goless without stackless or gevent available): goless works out of the box with PyPy (using stackless.py in its stdlib) and Stackless Python. It works seamlessly with gevent and CPython 2.7. It works with PyPy and gevent if you use the tip of gevent and PyPy 2.2+. It will support Python 3 as soon as gevent does.
Thanks and if you use goless, I’m eager to hear your feedback!