Running Python modules in Python, from Jython

大憨熊 提交于 2019-12-05 19:19:15

You should be able to use Pyro to send method calls and their return data between Jython and CPython. It's designed so that "objects can talk to each other over the network" but there's no reason the same technique shouldn't work between two different types of Python on a single machine.

In the Pyro documentation you will find a simple example which shows you just about everything you need to know to get this up and running.

You should take a look at

Both are frameworks designed exactly for the purpose you demand. Also keep an eye on JyNI (www.jyni.org) which is still in an early state, but will vastly improve Jython-support for a vast amount of Python-frameworks.

Using Pyro (https://pypi.python.org/pypi/Pyro4) you will probably also be able to solve your task, but keep in mind that it was not actually designed for this purpose but for distributed network stuff. This can yield subtle issues (e.g. poor performance) rendering it an edgy solution. This must not necessarily be the case, but I would recommend to prefer a solution intended for a task if one is available. However take this just a hint and humble warning as I did not actually compare the named approaches in practice.

You can avoid Jython altogether and still talk to python via Pyro, by using Pyrolite in your Java code. Pyrolite is a lightweight client library that lets your java program talk directly to Pyro. Will work as long as your java program is only a Pyro client.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!