Using Pyro together with Jython
In the past, there used to be some comments on this page about problems in Jything that prevented Pyro to work with it at all, but a lot has been changed since then (Jython has been updated a lot, Pyro and Python itself have seen updates too). I invite you to post about your experiences with using Pyro in Jython below (or on the mailing list as usual). I will try to organise this page now and then to reflect the current known status of using Pyro in Jython.
For starters: Setting it up to use Pyro in Jython: /SettingUp
Note: you need at least Pyro 3.8 to be able to run a Pyro server in Jython
Current status
There are a few issues:
- checksumming doesn't work in Jython (PYRO_CHECKSUM must not be set)
- pickling errors in Jython when talking to CPython (you have to set PYRO_PICKLE_FORMAT to 1)
- nameserver discovery using broadcast doesn't work
the timeout feature (setTimeout()) causes unreliable behavior so it may not be used from Jython code
- problems with select()
- Can't run Naming Service or Event Service in Jython
See below.
1. checksum problem causes weird TypeError
Enabling checksums (Pyro.config.PYRO_CHECKSUM=1) causes errors.
analysis / solution
Caused by a bug in Jython's implementation of the zlib.adler32 function. See Jython issue tracker: http://bugs.jython.org/issue1033 Alan Kennedy says: A fix for this issue has been checked into the jython source tree at revision 4441, and will appear in the next release of jython. If you want to patch an existing jython 2.2.1 install before that release, then change the definition of the adler32 function in the zlib module to look like this
def adler32(s, value=1):
if value != 1:
raise ValueError, "adler32 only support start value of 1"
checksum = Adler32()
checksum.update(String.getBytes(s, 'iso-8859-1'))
return Long(checksum.getValue()).intValue()More information from the jython bug tracker: http://bugs.jython.org/issue1033
So the solution is to use Alan's patch, or don't use the checksum feature at all until the next Jython version is released. (Note that Pyro 4 will no longer have the checksum option so the problem won't occur there).
2. problems with data returned from server, pickle problems
Sometimes pickling errors occur or the data gets mangled (dictionaries get scrambled, tuples get truncated, stuff like that). It occurs when you have CPython on one end, and Jython on the other end.
analysis / solution
This is caused by a different Python implementation that is sending the response to your Jython client (it is CPython on the server side). It seems that Jython's pickle module cannot deal with the binary pickles that CPython produces when using pickle protocol 2 or higher. That protocol level is the default level that Pyro uses because it looks at the pickle.HIGHEST_PROTOCOL constant. Unfortunately, Jython doesn't provide that magic constant so Pyro assumes 1 in this case. Jython also doesn't report an error when using an unsupported pickle protocol level.
Workaround: tell Pyro to fall back to protocol level 1: set the config item PYRO_PICKLE_FORMAT to 1. (on the server, where you run cpython). This seems to work fine (at least, the offending test code passed without errors this time).
3. nameserver discovery using broadcast doesn't work
Using the broadcast mechanism of the NameServerLocator to locate the name server doesn't work on Jython, so this feature has been disabled. It will print a trace message instead and the locator will continue its lookup using conventional methods.
Cause:
Jython doesn't support broadcasts on UDP sockets. Jython's socket module doesn't provide the SO_BROADCAST socket option, and sending a UDP packet to the broadcast address 255.255.255.255 will result in error: (-1, 'Unmapped exception: java.net.SocketException')
4. timeout feature causes unreliable behavior
When using Pyro's timeout feature (setTimeout() call) you trigger unreliable behavior in Jython. So this feature may not be used from Jython code. It will throw a RuntimeException.
The exact problem is that enabling timeouts triggers the use of select(), and that is at this time not yet very stable in Jython. You will get the select() errors mentioned in the following section. must provide some sample code and stacktrace to be able to debug
5. problems with select()
Sometimes you get crashes like this:
File "E:\jython\Lib\select.py", line 59, in __init__
self.selector = java.nio.channels.Selector.open()
java.io.IOException: java.io.IOException: Unable to establish loopback connection
analysis / solution
No idea
must provide some sample code and stacktrace to be able to debug
6. Can't run Naming service or Event service
Running either of these is not (yet) supported in Jython. I've seen some rather weird errors when attempting to run the name server, and I can't explain nor fix these errors at this moment. Errors include crash with UnboundLocalError: local: 'globals' must provide some sample code and stacktrace to be able to debug
