Wednesday, September 5, 2007

CherryPy 3 + Jython - Third attempt

OK, so it's been a while since I had time and energy to give this another shot. But Leo Soto's work on Django and Jython gave me some inspiration the other day. So I pulled down the latest svn version of Jython (since 2.2 is released now, trunk is the former 2.3 branch). Since the last time I tried this Alan Kennedy has supplied some excellent improvements to Jython's socket module, so I was hoping most of my problems would be solved.

I started off with a clean Jython and clean CherryPy (3.0.2). I realised right away that the metaclass problem mentioned in the previous post still existed, so I made the same fix as before. I also noticed that Jython is still missing a signal module, so I dummied one up for my purposes. Afters some trial and error I added three things to the Jython socket module: the _fileobject class (just copied it from CPython) and the constants AF_UNSPEC and AI_PASSIVE.

Yay! It finally worked. To my joy the simple Hello World example ran without any problems :-)

import cherrypy

class HelloWorld:
def index(self):
return "Hello world!"
index.exposed = True

cherrypy.quickstart(HelloWorld())


The next step is of course to try out some more advanced CherryPy moves... more to come.

5 comments:

Pekka said...

This is really interesting even though I'm not even doing webstuff myself! Have you tried, or are you planning to try, this on 2.2 too? I know new stuff in the trunk is really exiting but it would be great if this worked also on latest stable release. There's been talks about 2.2.1 and some of the encountered problems could maybe be fixed already there.

H Eriksson said...

The biggest issue with 2.2 is the generator stuff. Lots of 'from __future__ import generators' would be needed.

Leo Soto M. said...

Congratulations! That opens so many possibilities. I'm sure we will have more exciting news soon :).

Keep up the good work!

Alan Kennedy said...

That's great to hear.

Any chance you would consider contributing that dummy signal module?

You could write it up on a wiki page

http://wiki.python.org/jython/ModulesOverview

or report it as a bug in jython, "Signal module is not supported", and attach the module as a patch.

http://bugs.jython.org/

H Eriksson said...

Well, it's really nothing to contribute. Just to get what I was working on to run all I had to do was create a signal.py file with a signal function that took two arguments and just printed a warning...