Jython vs. Python


ultimate goal is a flashing LED in one of my wall mounted switches.

For testing thread behavior, I have the following code, which works fine with Python 2.7:

from threading import Thread
import time

class LedThread(Thread):
    def __init__(self):
        super(LedThread, self).__init__()
        self._keepgoing = True
        self.frequency = 1

    def run(self):
        while (self._keepgoing):
            print "LED blinking"

    def stop(self):
        self._keepgoing = False

mythread = LedThread()
print type(mythread)
mythread.frequency = 5

Type of mythread is reported as “<class ‘main.LedThread’>”

In Jython I get the error message “ttributeError: ‘org.python.core.FunctionThread’ object has no attribute ‘frequency’ in at line number 22”

In this case mythread is reported as “<type ‘org.python.core.FunctionThread’>”.

When I remove the line “mythread.frequency = 5” the code works as expected.

I have no clue, what is not OK with the code.

Thanks for your help!

FWIW, your code works for me using Jython 2.7.0 from the command line. I see…

<class '__main__.LedThread'>
LED blinking
LED blinking
LED blinking
LED blinking

My Jython version details are:

Jython 2.7.0 (default:9987c746f838, Apr 29 2015, 02:25:11)
[Java HotSpot™ 64-Bit Server VM (Oracle Corporation)] on java1.8.0_92

Same here: everything is fine when used with Python 2.7 from my system or Jython from the command line, but the error is shown when used from within a JSR223 rule…

Tested it with the Jython standalone Jar and the install package.

I am using Jython 2.7.0 and Oracle Java version “1.8.0_151” Java™ SE Runtime Environment (build 1.8.0_151-b12) on macOS 10.13.2