problematic jython

Geek

So I've spent this afternoon trying to embed Jython into a top-secret project. It has been a pain. A real pain.

First off, the API documentation is terrible. Most of the classes and methods aren't documented. Those that are, are poorly done. Luckily because Jython is free software, I had access to the source code and could browse through that, but I really shouldn't have to. If I get time, I may write some documentation comments for the core classes like PythonInterpreter and PySystemState.

Next, the implementation is a hive of static properties and methods, thread-local variables, global initialisers and multiple API entry-points. Apparently multiple instances of PythonInterpreter are thread-safe, but can I have multiple instances of PySystemState, each initialised differently in one virtual machine? Is a single instance of PythonInterpreter and the Python objects it contains thread safe? What I'd like to see is Python code interpreted/compiled to thread-safe bytecode. To execute it, you pass it to objects that represent local and/or system state that your application maintains itself. No static or thread-local variables, a clear entry point that can be synchonized if need be and a clear way for the application to maintain state itself.

In the end however, the Jython's dependency on the file system has been the real killer. I can't see any need for it to require a cache directory - compiled scripts should be passed to a class loader directly as bytecode. The library scripts should have been compiled into classes and assembled as a JAR when the distribution was packaged. They should be able to be found by just putting that JAR in the classpath. But why on earth does Jython need to be able to locate classes and JARs in the filesystem if it loads them from a class loader anyway? I still can't get it to import my web application's classes for use in a script.

I hate to admit it, but I'm thinking of using ECMAScript (nee JavaScript) for the project's scripting needs instead. Rhino suffers some of the same problems as Jython but at least Rhino is well documented and easy to embed.

Posted Sunday, February 6, 2005 at 19:27.

TrackBacks

TrackBack URL for this post: http://volition.vee.net/mt/mt-idle-trackback.cgi/404

Comments

Indeed. The filesystem dependency (that and a few classloading blues) is what made me finally abandon Jython for anything other than quick prototyping and test harnesses.

It's a hassle %(

Posted by: Joel on February 7, 2005 08:34 PM

PS - was it you who put me onto BeanShell, Mike? I haven't used it lately, but it was certainly worky when I did.

Posted by: Joel on February 7, 2005 08:36 PM

Maybe, maybe. I use BSH pretty frequently from the command line for odd jobs, maybe boot-strapping an object model, running those throw-away snippets that I should probably be keeping, etc, etc.

I don't really want to embed BSH, however. If I'm going to the trouble of embedding a scripting language then I want to get /some/ benefit from it. If I'm using BSH, I may as well write and compile a real class.

Still, I really should put my money where my mouth is and use JRuby, but I've got Jython embedded and working reasonable well now, so JRuby will have to wait for another rainy day.

Posted by: Mike on February 8, 2005 12:51 AM

... although it seems that JRuby is two point releases away from being able to implement Java classes in Ruby, which is kind of annoying and a bit of a blocker.

Posted by: Mike on February 8, 2005 01:01 AM

Add a Comment



(Optional)


(Optional)


Preview your comment before submitting.