从 Java 控制 Jython 脚本的执行

发布于 2024-07-06 23:17:18 字数 309 浏览 4 评论 0原文

我试图从 Java 内部控制 Jython 脚本的执行,并通过调用 PythonInterpreter.exec() 来执行。 该脚本包含对 Java 中定义的类的调用。 为了在这里讨论,我将这些类称为“命令”。 这些命令还可以通过 RMI 在不同的计算机上运行。

由于命令需要一段时间才能完成,因此我想在调用方检查命令执行的进度,例如执行完成的百分比。 我可以为类提供 getProgress() 方法,但访问此方法似乎是不可能的,因为 PythonInterpreter 不允许调用者访问在其中运行的命令对象。

关于如何做到这一点有什么想法吗?

I'm trying to control the execution of a Jython script from within Java and executed through a call to PythonInterpreter.exec(). The script contains calls to classes defined in Java. I'll call these classes "commands" for the discussion here. The commands can also be run on a different machine via RMI.

Since the commands take a while to complete, I want to check the progress of the commands' execution on the caller side, like at what percentage of the execution is complete. I can provide a getProgress() method to the classes but accessing this method seems to be impossible to do because PythonInterpreter doesn't allow the caller access to the command object running inside it.

Any ideas on how to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

擦肩而过的背影 2024-07-13 23:17:18

我的 0.10 欧元:
(这并不容易)

中的描述构建一个工厂

按照http://wiki.python .org/jython/JythonMonthly/Articles/September2006/1

和表示脚本类 (IJScript) 的 Java 接口
(包括 run() 和 getProgress() 方法)

您的脚本应该如下所示:

class xyscript(IJScript) :

def __init__(self) :
   ...
def run(self) :
   ...
def getProgress(self) :
   ....

在访问 IJScript 接口(Java 接口)时运行您的脚本
(看员工的例子)

my 0.10 Eur :
(ist not easy)

Build a Factory as descripted in

http://wiki.python.org/jython/JythonMonthly/Articles/September2006/1

and a Java-Interface that represents a script-class (IJScript)
(including run() and getProgress() methods)

your scripts should then look like this:

class xyscript(IJScript) :

def __init__(self) :
   ...
def run(self) :
   ...
def getProgress(self) :
   ....

run your scripts in accessing the Interface IJScript (the Java Interface)
(look at the employee example)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文