Announcing Greenlet 0.3

March 23, 2010

I’ve just released greenlet 0.3 on pypi. which has some bug fixes and a couple of new features.

Python 3 support

Greenlet now supports Python 3, and has been tested on Python 2.4, 2.5, 2.6, 3.0 and 3.1 on all platforms I have access to (x86 and amd64 GNU/Linux, x86 Windows, and Mac OS X Leopard).

Existing tests were rewritten so that they could be run without nose, since there is currently no stable release of nose for Python 3.

switch() now accepts keyword arguments

This is from the DWIM department. The switch method will now do what you expect with the arguments it receives.

>>> greenlet.greenlet(lambda: greenlet.getcurrent().switch()).switch()
>>> greenlet.greenlet(lambda: greenlet.getcurrent().switch(1)).switch()
>>> greenlet.greenlet(lambda: greenlet.getcurrent().switch(1, 2)).switch()
(1, 2)
>>> greenlet.greenlet(lambda: greenlet.getcurrent().switch(a=5)).switch()
{'a': 5}
>>> greenlet.greenlet(lambda: greenlet.getcurrent().switch(1, 2, a=5)).switch()
((1, 2), {'a': 5})


If you are writing an extension module, you can now use the provided header file to import greenlet, create greenlet objects and modify them directly from C.

PyObject *callable = ...
PyGreenlet *g = PyGreenlet_New(callable, NULL);
PyGreenlet_Switch(g, NULL, NULL);
    Py_BuildValue("s", "error message"),

See the documentation for a full API reference.

Platform updates

  • Linux mips support from Thiemo Seufer
  • MingGW GCC 4.4 support from Giovanni Bajo
  • Arm32 support from Sylvain Baro
  • Fixed Python 2.6 support on Windows from Armin Rigo

Bugs fixed

  • Switching to a new inactive greenlet created in another thread no longer crashes Python.
  • Fix for issue #40 from py lib to fix a threading bug. Patch from Armin Rigo and ghazel.

Documentation and tests

This release tripled the number of unit tests, and includes updated documentation based on the docs that used to be included in the py lib.

Known issues

  • #4: Build currently broken on Solaris Spark
  • #2: No support for x64 Windows
  • #5: No GC support. Creating reference cycles that include data in the stack frame of a greenlet can lead to leaks.

Getting greenlet

On most platforms, getting greenlet is easy. Just use pip or easy_install.

pip install --upgrade greenlet
easy_install -U greenlet

On Windows installing greenlet can be kind of tricky, since (without hackery) Visual Studio 2003 is required for Python versions < 2.6, and Visual Studio 2008 is required for later versions. For those who don’t want to go through the trouble, I’ve uploaded binary eggs and installers for x86 Windows to pypi, and the download page.

If you would like to report any bugs or request a feature, please create a new issue on bitbucket.

Extension modules for unit tests with distutils

March 22, 2010

I’ve been hacking on greenlet lately, which has been in dire need of some tender loving care. The upcoming 0.3 release will include an API for extension modules that allows any extension module to create and manipulate greenlets directly in C without jumping through hoops.

I found myself wanting to add a test extension module to bring the C API under test, but it turns out that distutils doesn’t really support building extension modules that you don’t want to ship in the resulting binary distribution. In fact, when you run “ install”, distutils just copies the contents of build/lib.<platform>-<pyversion> to the target package.

The solution I came up with was pretty lame. greenlet has a tests package that provides a test collector function. Since some of the tests require an extension module to be built, the test collector will call tests.build_test_extensions(), which will manually compile the extension modules using distutils the same way that distutils.command.build_ext will, except that the resulting shared library is staged in build/temp.<platform>-<pyversion> before being copied into the source root.

The end result is similar to just adding the extension to, except that the test extensions don’t get installed. I’m definitely reporting this as a feature request for distutils2.


Get every new post delivered to your Inbox.