Sunday, March 16, 2008

The next step to increase Python compatability in Jython

Last night at PyCon, at the Jython dinner (thanks goes to Sun for feeding us), we followed up a discussion from earlier during the day about Python and concurrency. We realized that CPython is far ahead of us in this area, and that we are lacking in compatibility. After serious brainstorming (and a few glasses of wine), we decided that introducing a Global Interpreter Lock in Jython would solve the entire issue! I hacked together an implementation, while we were having coffee, that is now in trunk. To ensure that this does not break any old code written for Jython the GIL is added as a future feature. To get GIL support today, check out the Jython trunk, start the interpreter, then type:
from __future__ import GIL
Happy hacking!


mikeyp said...

Good work, but shouldn't that be:

from __future__ import JIL

It would prevent confusion with the C-Python GIL, and leave open a path to implementing future enhancements.
like a lock for each individual Java thread.

Jim Baker said...

Some had complained that Jython would out perform CPython, especially for concurrency. So
let's check out this awesome feature in trunk (thanks Tobias!):

Jython 2.3a0 on java1.5.0_13
Type "copyright", "credits" or "license" for more information.
>>> from __future__ import GIL
Traceback (innermost last):
(no code object) at line 0
File "..console..", line 0
SyntaxError: Never going to happen!

I guess that describes concisely what our support for the global interpreter lock is: we don't have one, and we never will.