Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Migrating from CPython to Jython

Tags:

I'm considering moving my code (around 30K LOC) from CPython to Jython, so that I could have better integration with my java code.

Is there a checklist or a guide I should look at, to help my with the migration? Does anyone have experience with doing something similar?

From reading the Jython site, most of the problems seem too obscure to bother me.

I did notice that:

  • thread safety is an issue
  • Unicode support seems to be quite different, which may be a problem for me
  • mysqldb doesn't work and needs to be replaced with zxJDBC

Anything else?

Related question: What are some strategies to write python code that works in CPython, Jython and IronPython

like image 951
itsadok Avatar asked Jan 07 '09 15:01

itsadok


People also ask

How is CPython different from Jython?

Difference between Python and JythonReference implementation of Python, called CPython, is written in C language. Jython on the other hand is completely written in Java and is a JVM implementation. Standard Python is available on multiple platforms. Jython is available for any platform with a JVM installed on it.

Is Jython still maintained?

Jython was started by Jim Hugunin in 1997 as “JPython”, and has seen continued development since then. However, development of Jython is remains on the Python 2.7 line, a major release of the Python interpreter which, since the beginning of 2020, is no longer being maintained.

How is CPython different from IronPython?

Just as Jython is an implementation of Python on the JVM, IronPython is an implementation of Python on the . Net runtime, or CLR (Common Language Runtime). IronPython uses the DLR (Dynamic Language Runtime) of the CLR to allow Python programs to run with the same degree of dynamism that they do in CPython.

Is Jython a Python?

Jython is a version of the Python programming language that runs on the Java platform. It allows users to write programs in Python and compile them to Java bytecodes that run directly on a Java Virtual Machine, or JVM.


1 Answers

First off, I have to say the Jython implementation is very good. Most things "just work".

Here are a few things that I have encountered:

  • C modules are not available, of course.

  • open('file').read() doesn't automatically close the file. This has to do with the difference in the garbage collector. This can cause issues with too many open files. It's better to use the "with open('file') as fp" idiom.

  • Setting the current working directory (using os.setcwd()) works for Python code, but not for Java code. It emulates the current working directory for everything file-related but can only do so for Jython.

  • XML parsing will try to validate an external DTD if it's available. This can cause massive slowdowns in XML handling code because the parser will download the DTD over the network. I reported this issue, but so far it remains unfixed.

  • The __ del __ method is invoked very late in Jython code, not immediately after the last reference to the object is deleted.

There is an old list of differences, but a recent list is not available.

like image 186
Frederik Avatar answered Oct 04 '22 14:10

Frederik