Jython 2.5.2 Beta 2 is Released

September 13, 2010 at 11:47 PM | categories: Jython, 2.5.x | View Comments

On behalf of the Jython development team, I would like to announce the second beta release of the 2.5.2 version of Jython. Our current plan is that this will be the last beta of 2.5.2, but this will depend on bug reports.

Download the installer JAR from SourceForge. Here are the checksums:

  • MD5, 560b43678059fd41a374a9487517235c
  • SHA1, 0c41db0e5d275bff80a2c4f9bc3de2e48969d0a6

The release was compiled on Mac OS X with JDK 5 and requires JDK 5 to run. Please try it out and report any bugs at http://bugs.jython.org.

This release fixes bugs related to resource leaks, Java integration, and a number of other issues. See the NEWS for more details. In particular, we did not completely fix the bug, Classloaders cannot GC, which exhausts permgen. Jython uses instances of ThreadState to manage its execution state, including frames, exceptions, and the global namespace. The ThreadState also indirectly refers to the ClassLoader objects used by Jython. Such usage can cause resource leaks when a Jython application is restarted under certain app containers, because the ThreadState often may not removed by the app server's thread pool. This is because ThreadState itself is managed by Java's ThreadLocal.

Fixing this problem without a backwards breaking API change appears to be difficult. Therefore we recommend exploring workarounds, such as the one published in this blog post, which also goes into these issues in more depth.

Jython 2.6 will introduce limited backwards breaking API changes, so it will be possible to fully resolve this bug, and related issues, in that version instead. In a future blog post, I will address what we can do with respect to ThreadState in our 2.6. work.

Let's turn to more on what has been fixed or extended in 2.5.2. In particular, I would like to highlight the following:

  • JSR 223 (javax.script) support was introduced in 2.5.1, but it's now fully usable and is supported by such solutions as RESTx, which runs on Mule ESB. In particular, we bundle our own JSR 223-compliant engine to interface with Jython. Much thanks goes to Jim White who kept pushing us -- and other implementations -- on this and provided us with the starting code; Nicholas Riley, who did much of the work on the Jython development team; and the many beta testers who provided valuable advice and bug reports. JSR 223 is an important, cross-language integration point.

  • Python functions can be directly passed to Java methods that take a single method interface (such as Callable or Runnable). This means you can now pass a callback function, usually a closure, instead wrapping it in a class implementing that interface. Tobias Ivarsson implemented this feature.

  • The collections.defaultdict type is now fully threadsafe. This change continues a trend with our 2.5.0 release to provide strong support for concurrent Python code. Previously any default values could be overwritten by competing threads. CPython is able to implicitly provide the same guarantees, but only on built-in type factories, by the fact that code is serialized through the use of its Global Interpreter Lock (GIL). Jython now uses Google Guava's support for collections. In particular, we leverage atomically computed function maps.

  • Jython's console now supports completing user input upon pressing the <TAB> key. Using JLine, which we have bundled since 2.5.0, means completion works on both Windows and Unix-derived platforms (including Linux and OS X). Use it just like in CPython:

    import readline
    import rlcompleter
    readline.parse_and_bind("tab: complete")

    Usually you would do this in a setup script or a Python shell like IPython. For now, you will also need to change a property setting. See the tracking issue on the specifics, but we hope to have this and IPython support complete, so to speak, by 2.5.2 final.

    Such completion is particularly useful in navigating Java APIs, most of which tend to be complex.

  • You can now call a Java constructor using keyword arguments. Geoffrey French contributed the patch for this nice feature. It will also be the last new feature implemented in the 2.5.x versions!

There are many other features and bug fixes, some small, some large. We will look at these in future posts, as well as some outstanding bugs we should be able to fix before the final release.

And -- last but not least -- please help spread the word:

Organizations using Jython 2.2.1, or earlier, should test their code against 2.5.2 beta 2 now so that bug fixes and/or workarounds may be identified. In particular, please note the following:

  • No additional work is anticipated on Jython 2.2.
  • Jython 2.5.2 is the last release in Jython 2.5.x series that will address non-severe issues. Further enhancements in Java integration, for instance, will be seen in 2.6.
  • Jython 2.6 development will begin immediately following the 2.5.2 release. Jython 2.6 will require the use of JDK 6. We are hoping for some significant performance gains by being able to use invokedynamic support, either directly or through a back port of that support to JDK 6. More also on that in a future post.
Read and Post Comments

Flipping the 2.5 Bit for Jython

June 24, 2008 at 10:59 AM | categories: Jython, 2.5.x | View Comments

Something worth pointing out; as of 8 AM this morning (MDT) in rev 4748, Frank Wierzbicki flipped the bits and pronounced this about the ASM branch:

jbaker:~/jythondev/asm jbaker$ dist/bin/jython
Jython 2.5a0+ (asm:4750, Jun 24 2008, 10:56:16)
[Java HotSpot(TM) Client VM ("Apple Computer, Inc.")] on java1.5.0_13
Type "help", "copyright", "credits" or "license" for more information.

Yesterday there were easily the most commits we have seen in the Jython project. The real threshold was reached when we incorporated the UTF-16 and new-style exception branches into this branch, fixed the grammar to support most incremental parses, while repointing the standard library to CPythonLib 2.5. Along with a flurry of other fixes!

There's a lot more to go, but this should be an encouraging sign for everyone interested in Jython!

Read and Post Comments

Realizing Jython 2.5

June 20, 2008 at 09:43 PM | categories: Jython, 2.5.x | View Comments

Jython 2.5 is really, finally, unbelievably coming together. This is the next release of Jython, after last summer's 2.2. In a nutshell, we have completed all new language features using an Antlr parser, except for absolute imports. All bytecode generation work, now using an ASM backend, is done. Of course, there are many outstanding bugs. And Python is not just a core language; we need to support fully the fact that "batteries are included". But let's look at where we are. Through the prism of what's new in 2.3, 2.4, and 2.5, here's what working:

  • 2.3: sets (PEP 218), generators (255), source code encoding (263), universal newline (278), enumerate (279), logging (282), Boolean (285), distutils (301), new import hooks (302), pickle enhancements (307), extended slices, datetimes, optparse. Still to go: csv, removing a dictionary in builtin that ensures that interned strings don't get in GC'ed (pre-2.3 behavior!, it helps to read what's new). Also various string, Unicode, and regex changes are mostly done in a separate utf16 branch that I'm currently in the midst of merging against trunk.
  • 2.4: unifying long integers (237), generator expressions (289), string.Template (292, but also needs new utf16 work), decorators (318), reverse iteration (322), subprocess module (324), multi-line imports (328), removal of OverflowWarning, min & max with keyword support, sorted. But we still need partial import with sys.modules, and I'm sure some more stuff I forgot. Decimal and -m support are working in student branches, we just need to incorporate.
  • 2.5: conditional expressions (308), partial functional (309, but we're cheating with a pure-Python version), distutils metadata (314), unified try/except/finally (341), coroutines and other generator functionality (342), with-statement, including contextlib (343), any, all. But we haven't done the exceptions remapping to new-style classes, absolute and relative imports, or all of the context manager support, such as in file. ctypes was a proposed Google Summer of Code project, but apparently PyPy has some work that's 95% the way there; we will talk with them at EuroPython. We need to look into what is necessary to make ElementTree work. sqlite3 depends on ctypes. As I was writing this, I tried out wsgiref; it works and I just committed it to the asm branch. (At some point, we will repoint everything like this to CPythonLib, but for now we are mixing it up as we go. Bear with us!)

Even quit() and exit() now work; I don't know when these oh-so-major features were added. We even now support large string constants. And of course, who can forget our support for the GIL (global interpreter lock) in Jython, something that Tobias Ivarsson, my Google Summer of Code student who is now working on an advanced compiler, added to __future__ as an Easter egg:

>>> from __future__ import GIL
Traceback (most recent call last):
  (no code object) at line 0
  File "<stdin>", line 0
SyntaxError: Never going to happen!

I would imagine that's definitive, we go against Java's native threads and compile to Java bytecode. It would be hard to have a GIL, even if we wanted one.

However, we are just turning the corner. The The Antlr parser in the asm branch currently does not support partial parses, and this breaks not only interactive sessions but doctests. Until this is solved - and Frank Wierzbicki is working like mad on this - we can't merge this branch onto trunk. But that should happen very soon.

With few exceptions, we simply go against the standard Python unit tests. Straightforward, cunning, or devious, we have labored against these unit tests. And in others, we have used Python as our foil: we support the same 2.5 AST parse tree, and we know this by comparing our parses with CPython's for all of the standard library - including those unit tests.

There's a lot more going on. I can't say enough about the work done by Charlie Groves, Philip Jenvey, Alan Kennedy, Nicholas Riley, and others to make this happen. Leo Soto, my other GSoC student, is making amazing progress on supporting Django on Jython, while finding and fixing bugs in Jython itself. Supporting Django forces us to find those gaps in compatibility. Similar efforts are going on with Pylons, TurboGears 2 (Ariane Paola, GSoC), and Zope (Georgy Berdyshev, GSoC). I'm also working on greenlet/Stackless support and involved in a collaboration with Jeremy Siek and Joe Angell at the University of Colorado to add gradual typing] (yes types! but only when you want to) to Jython. We have a T2000 contributed by Sun to let us see how much concurrency - in this case 32 hardware threads, 64 GB of memory - Jython can take advantage of. And so on.

Back to work!

Updates - 2008-06-24: we have support for new-style exceptions, the parser is now usable (but there are a couple of bugs left there), and Unicode support has been updated to UTF-16. See this posting, Flipping the 2.5 Bit for Jython.

Read and Post Comments

Django on Jython - Minding the Gap

January 03, 2008 at 09:59 PM | categories: Jython, 2.5.x | View Comments


The most important thing to know about Django on Jython is that we are almost there, and with clean code. End-to-end functionality is demonstrated by the admin tool running in full CRUD, along with a substantial number of unit tests and syncdb. But this has been achieved by so far requiring only 6 lines of code in changes to Django trunk. (There will be more, however, see below.)

Running on Jython

To run Django on Jython, with a PostgreSQL backend, the following steps are necessary:

  • Use the Modern branch of Jython. This consolidated the bugs, workarounds, and patches of numerous people -- plus a bunch more -- in a stable, almost-ready-to-be-merged-into-trunk version of Jython. The most important aspect is that we have tried to make Jython conform more to CPython, using Django as our guide, although there are some gaps -- especially if Django already had incorporated fixes. Our driving goal is to converge on these gaps over time. Please note that is intended to be stable, performant code.
  • Use the Django trunk (tested with rev 6992, later should be OK too).
  • Apply these two patches, django.dispatch.robustapply (diff) and django.views.debug (diff) due to Leo Soto. I would imagine these will be in Django trunk soon.
  • Copy these three files from CPythonLib to Lib: gettext.py, locale.py, optparse.py. Please note that these files are only partially working on Jython, that's why they haven't been promoted yet (gettext.py actually works, as verified by test_gettext.py, but depends on still failing locale.py). But they are very close, and they appear to be fine for Django. Certainly fine for this round of development!
  • Use the database backend zxjdbc_postgresql, which was contributed by Leo Soto. Frank Wierzbicki has an experimental backend for MySQL, this should be incorporated soon.


Here's what works:

syncdb and the very cool Django admin run; many unit tests pass. You can run with internationalization enabled. You do need to run the dev server with --noreload for now. We need to document here how to run with modjy, which is Alan Kennedy's servlet container for WSGI apps.

In running the model unit tests, here are the things we seem to be missing, accounting for most of the approximately 75 failures:

  • Many doctests are fragile, because they depend on the dict traversal ordering; in Jython, this is different that CPython, and if we adopt ConcurrentHashMap, it's not even repeatable. This would seem to be a pervasive bug in Django.
  • We still have some encoding problems, again seen in doctests. An example where output is expected to be lower case hex, not upper case. I fixed the problem in PyUnicode, but there are more places.
  • Problem with the ManagerDescriptor handling, in django.db.models.manager.
  • No decorators yet! (But they are coming soon, and are now available experimentally for Jython in the newcompiler work I have been leading.)

There may be some other rough categories, we need to look at the failures more systematically. All that doctest noise is certainly annoying!

Next Steps

On the Django front, get more of the unit tests running!

Before we can push modern into trunk, the following needs to be done:

  • The test_extcall unit test currently fails. This appears to be a dependency on dict traversal being repeatable, a bad assumption. However, it's a mind bending test. The 2.3 version is particularly problematic because it's not modular at all. Google's GHOP has just produced an improved version for Python 2.6 - we will look at this as a starting point.
  • Tristan King provided a near complete subset of the functionality for time.strptime, as implemented in org.python.modules.time.Time. This needs to be enhanced. I just tested this, and all unit tests in the CPythonLib version of test_time now pass except for strptime -- specifically the conversion specifier '%c' -- so we can also move to that, and discard our Jython version, when this is completed. That should be soon!
  • Decide whether we should use ConcurentHashMap or not as the backing hash map for dict and __dict__. CHM introduces creation overhead, but it should prove to be far more scalable on multicore systems. The programming model is also far nicer with respect to Jython.

Updates - 2008-06-24: I should have put this up a while ago, but Django on Jython is becoming a reality. Most importantly, Leo Soto is working with me through the Google Summer of Code on this project. The modern branch was merged into a trunk earlier this year, and has since been retired. CHM in fact has the right semantics, something I may discuss at a future point. Django has redone the doctest dict literals that were causing problems, and Leo provided a general solution when used with XML/XHTML.

Updates - 2010-09-13: Django on Jython is a standard PyPI project. The best reference for it can be found in our Jython book. Jython 2.5.2 is about out. The previous release fixed pretty much all of the other issues. And using ConcurrentHashMap has been a very good decision!

Read and Post Comments