Migrating from CPython to Jython

后端 未结 6 459
时光取名叫无心
时光取名叫无心 2020-12-29 04:26

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

6条回答
  •  無奈伤痛
    2020-12-29 05:15

    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.

提交回复
热议问题