<tfoot id='z6OjG'></tfoot>
  • <small id='z6OjG'></small><noframes id='z6OjG'>

      <i id='z6OjG'><tr id='z6OjG'><dt id='z6OjG'><q id='z6OjG'><span id='z6OjG'><b id='z6OjG'><form id='z6OjG'><ins id='z6OjG'></ins><ul id='z6OjG'></ul><sub id='z6OjG'></sub></form><legend id='z6OjG'></legend><bdo id='z6OjG'><pre id='z6OjG'><center id='z6OjG'></center></pre></bdo></b><th id='z6OjG'></th></span></q></dt></tr></i><div id='z6OjG'><tfoot id='z6OjG'></tfoot><dl id='z6OjG'><fieldset id='z6OjG'></fieldset></dl></div>
      • <bdo id='z6OjG'></bdo><ul id='z6OjG'></ul>

      <legend id='z6OjG'><style id='z6OjG'><dir id='z6OjG'><q id='z6OjG'></q></dir></style></legend>

        从 CPython 迁移到 Jython

        Migrating from CPython to Jython(从 CPython 迁移到 Jython)
        <legend id='ui6jG'><style id='ui6jG'><dir id='ui6jG'><q id='ui6jG'></q></dir></style></legend>
          <tbody id='ui6jG'></tbody>

        <tfoot id='ui6jG'></tfoot>
        <i id='ui6jG'><tr id='ui6jG'><dt id='ui6jG'><q id='ui6jG'><span id='ui6jG'><b id='ui6jG'><form id='ui6jG'><ins id='ui6jG'></ins><ul id='ui6jG'></ul><sub id='ui6jG'></sub></form><legend id='ui6jG'></legend><bdo id='ui6jG'><pre id='ui6jG'><center id='ui6jG'></center></pre></bdo></b><th id='ui6jG'></th></span></q></dt></tr></i><div id='ui6jG'><tfoot id='ui6jG'></tfoot><dl id='ui6jG'><fieldset id='ui6jG'></fieldset></dl></div>

              <bdo id='ui6jG'></bdo><ul id='ui6jG'></ul>
            • <small id='ui6jG'></small><noframes id='ui6jG'>

                  本文介绍了从 CPython 迁移到 Jython的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  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

                  解决方案

                  I'm starting this as a wiki collected from the other answers and my experience. Feel free to edit and add stuff, but please try to stick to practical advice rather than a list of broken things. Here's an old list of differences from the Jython site.

                  Resource management

                  Jython does not use reference counting, and so resources are released as they are garbage collected, which is much later then you'd see in the equivalent CPython program

                  • open('file').read() doesn't automatically close the file. Better use the with open('file') as fp idiom.
                  • The __ del __ method is invoked very late in Jython code, not immediately after the last reference to the object is deleted.

                  MySQL Integration

                  mysqldb is a c module, and therefore will not work in jython. Instead, you should use com.ziclix.python.sql.zxJDBC, which comes bundled with Jython.

                  Replace the following MySQLdb code:

                  connection = MySQLdb.connect(host, user, passwd, db, use_unicode=True, chatset='utf8')
                  

                  With:

                  url = "jdbc:mysql://%s/%s?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull" % (host, db)
                  connections = zxJDBC.connect(url, user, passwd, "com.mysql.jdbc.Driver")
                  

                  You'll also need to replace all _mysql_exception with zxJDBC.

                  Finally, you'll need to replace the query placeholders from %s to ?.

                  Unicode

                  • You can't express illegal unicode characters in Jython. Trying something like unichr(0xd800) would cause an exception, and having a literal u'ud800' in your code will just wreak havoc.

                  Missing things

                  • C modules are not available, of course.
                    • So no NumPy or SciPy.
                  • os.spawn* functions are not implemented. Instead use subprocess.call.

                  Performance

                  • For most workloads, Jython will be much slower than CPython. Reports are anything between 3 to 50 times slower.

                  Community

                  The Jython project is still alive, but is not fast-moving. The dev mailing list has about 20 messages a month, and there seem to be only about 2 developers commiting code lately.

                  这篇关于从 CPython 迁移到 Jython的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Running .jl file from R or Python(从 R 或 Python 运行 .jl 文件)
                  Running Julia .jl file in python(在 python 中运行 Julia .jl 文件)
                  Using PIP in a Azure WebApp(在 Azure WebApp 中使用 PIP)
                  How to run python3.7 based flask web api on azure(如何在 azure 上运行基于 python3.7 的烧瓶 web api)
                  Azure Python Web App Internal Server Error(Azure Python Web 应用程序内部服务器错误)
                  Run python dlib library on azure app service(在 azure app 服务上运行 python dlib 库)
                    <i id='H0yhv'><tr id='H0yhv'><dt id='H0yhv'><q id='H0yhv'><span id='H0yhv'><b id='H0yhv'><form id='H0yhv'><ins id='H0yhv'></ins><ul id='H0yhv'></ul><sub id='H0yhv'></sub></form><legend id='H0yhv'></legend><bdo id='H0yhv'><pre id='H0yhv'><center id='H0yhv'></center></pre></bdo></b><th id='H0yhv'></th></span></q></dt></tr></i><div id='H0yhv'><tfoot id='H0yhv'></tfoot><dl id='H0yhv'><fieldset id='H0yhv'></fieldset></dl></div>

                        <tbody id='H0yhv'></tbody>

                      <small id='H0yhv'></small><noframes id='H0yhv'>

                    1. <legend id='H0yhv'><style id='H0yhv'><dir id='H0yhv'><q id='H0yhv'></q></dir></style></legend>

                    2. <tfoot id='H0yhv'></tfoot>

                      • <bdo id='H0yhv'></bdo><ul id='H0yhv'></ul>