例如,我想在 Jython 中重现此线程,因为我需要从 Java API 启动我的状态机。我对Jython没有太多了解。我怎样才能做到这一点?
Thread thread = new Thread() {
@Override
public void run() {
statemachine.enter();
while (!isInterrupted()) {
statemachine.getInterfaceNew64().getVarMessage();
statemachine.runCycle();
try {
Thread.sleep(100);
} catch (InterruptedException e) {
interrupt();
}
}
}
};
thread.start();
所以我正在尝试这样的事情:
class Cycle(Thread, widgets.Listener):
def run(self):
self.statemachine = New64CycleBasedStatemachine()
self.statemachine.enter()
while not self.currentThread().isInterrupted():
self.statemachine.getInterfaceNew64().getVarMessage()
self.statemachine.runCycle()
try:
self.currentThread().sleep(100)
except InterruptedException:
self.interrupt()
self.start()
foo = Cycle()
foo.run()
#foo.start()
PS:我已经尝试过 foo.run() 下的评论
我究竟做错了什么?