[IronPython] CherryPy on IronPython up but not running

Sanghyeon Seo sanxiyn at gmail.com
Thu May 4 10:14:05 PDT 2006

I would like to share some of my progress on running CherryPy on
IronPython. Yes it starts up. No it doesn't process any request.

Following are steps to reproduce this result. I would be very
interested to here about your experience.

1. Install Mono

1.1.13.x versions won't work. This usually means you can't use Mono
packaged by your distribution.

For this howto I am using the Linux binary installer for x86, Mono
1.1.15_1, and I recommend you to use it too. It should work on any
Linux distributions, and does not require root privilege to install,
and uninstalls cleanly. If your platform is not x86, you should
compile from the source.

Of course if you are on Windows, you just need .NET 2.0 runtime, and
you can skip this step.

2. Download IronPython and CherryPy

I assume you know how to do these. I used IronPython 1.0 Beta 6 and
CherryPy 2.2.1.

3. Extract archive

>From now on I assume Unix-y command line. If you are on Windows
perform equivalent steps on that platform.

$ unzip IronPython-1.0-Beta6.zip
$ tar zxf CherryPy-2.2.1.tar.gz

4. Copy CPython libraries

This assumes you have CPython 2.4 installed on your system. I am using
Debian GNU/Linux package python2.4 version 2.4.3-3.

$ cd IronPython-1.0-Beta6
$ rm -rf Lib
$ cp -a /usr/lib/python2.4 Lib

5. Download my socket libraries

IronPython doesn't include built-in socket module yet, so I wrote one
myself. Download it and replace CPython's socket.py with it.

$ cd Lib
$ rm socket.py
$ wget http://sparcs.kaist.ac.kr/~tinuviel/fepy/lib/socket.py
$ wget http://sparcs.kaist.ac.kr/~tinuviel/fepy/lib/ssl.py

Let's move up.

$ cd ..
$ cd ..

6. Download my patches

patch-lib patches CPython standard library to workaround Mono bugs.
You don't need it if you are using MS.NET.

Details: IronPython uses .NET 2.0 GetEncodings() method to process
Python source file encoding declaration. This method is not
implemented in Mono. inspect.py, used indirectly by CherryPy, includes
source file encoding declaration.

$ wget http://sparcs.kaist.ac.kr/~tinuviel/fepy/ironcherry/patch-lib

patch-cherrypy patches CherryPy to workaround IronPython bugs, and in
one case, CPython dependency. Hopefully parts due to IronPython bugs
won't be needed in the future.

Details: IronPython currently lacks datetime.datetime class, so
_cputil.py patch rewrites timestamping code with time.strftime. For
various reasons sessionfilter won't work yet, so delete the code from
__init__.py and comment out the code from filters/__init__.py.
IronPython doesn't have zlib built-in module yet, so disable
gzipfilter. lib/cptools.py implements "safe eval" to read the config
file using the compiler package, which depends on CPython's internal
parser module, which I don't think IronPython can reasonably
implement. I replaced this with eval(). Finally, _cpengine.py is
patched to workaround IronPython's comparison bug. More on this bug

$ wget http://sparcs.kaist.ac.kr/~tinuviel/fepy/ironcherry/patch-cherrypy

7. Apply patches

$ cd IronPython-1.0-Beta6
$ patch -p0 < ../patch-lib
$ cd ..

$ cd CherryPy-2.2.1
$ patch -p0 < ../patch-cherrypy
$ cd ..

8. Download sample CherryPy application and configuration

test.py is just the simplest possible CherryPy application imaginable.

test.conf turns off autoreloading, because it uses os.spawnve which is
not yet implemented in IronPython.

$ cd CherryPy-2.2.1
$ wget http://sparcs.kaist.ac.kr/~tinuviel/fepy/ironcherry/test.py
$ wget http://sparcs.kaist.ac.kr/~tinuviel/fepy/ironcherry/test.conf

9. Run

$ mono ../IronPython-1.0-Beta6/IronPythonConsole.exe test.py

05/May/2006:2:10:16 CONFIG INFO Server parameters:
05/May/2006:2:10:16 CONFIG INFO   server.environment: development
05/May/2006:2:10:16 CONFIG INFO   server.log_to_screen: True
05/May/2006:2:10:16 CONFIG INFO   server.log_file:
05/May/2006:2:10:16 CONFIG INFO   server.log_tracebacks: True
05/May/2006:2:10:17 CONFIG INFO   server.log_request_headers: True
05/May/2006:2:10:17 CONFIG INFO   server.protocol_version: HTTP/1.0
05/May/2006:2:10:17 CONFIG INFO   server.socket_host:
05/May/2006:2:10:17 CONFIG INFO   server.socket_port: 8080
05/May/2006:2:10:17 CONFIG INFO   server.socket_file:
05/May/2006:2:10:17 CONFIG INFO   server.reverse_dns: False
05/May/2006:2:10:17 CONFIG INFO   server.socket_queue_size: 5
05/May/2006:2:10:17 CONFIG INFO   server.thread_pool: 10
05/May/2006:2:10:19 HTTP INFO Serving HTTP on http://localhost:8080/

Nice. Now access the site from the web browser, and you get...

05/May/2006:2:11:09 HTTP INFO Request Headers:
  ACCEPT-LANGUAGE: ko,en;q=0.5
  USER-AGENT: Mozilla/5.0 (X11; U; Linux i686; ko-KR; rv:
Gecko/20060326 Firefox/ (Debian-1.5.dfsg+
  ACCEPT-CHARSET: EUC-KR,utf-8;q=0.7,*;q=0.7
  HOST: localhost:8080
  ACCEPT-ENCODING: gzip,deflate
  CONNECTION: keep-alive
  ACCEPT: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Segmentation fault

And I'm stuck there.

Seo Sanghyeon

More information about the users mailing list