openhab-scripters / openhab-helper-libraries

Scripts and modules for use with openHAB
Eclipse Public License 1.0
88 stars 70 forks source link

Problem with helpers and Jython 2.7.1 #28

Closed sillyfrog closed 5 years ago

sillyfrog commented 5 years ago

I've been looking at moving from Jython 2.7.0 to Jython 2.7.1 (as it has built in pip - I think - and a number of other bug fixes), and am getting the traceback as per below.

I'm happy to look at this further, but not really sure where to start - so if you have any pointers, that would be great.

I found that if I remove the ...automation/lib/python/esper/java/esper-6.1.0.jar file, things appear to work, except for these errors (which is no surprise):

2018-10-21 10:30:45.768 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/openhab/conf/automation/jsr223/000_components/000_Esper.py': ImportError: No module named espertech in <script> at line number 12
2018-10-21 10:30:59.616 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/openhab/conf/automation/jsr223/000_components/100_ExampleExtensionProvider.py': ImportError: cannot import name JythonExtensionProvider in <script> at line number 1

The hello_world.py example still works, and is logging every 10 seconds.

I'm running things just as outlined in the Docker.md file, except with the jython 2.7.1 .bin (from http://search.maven.org/remotecontent?filepath=org/python/jython-standalone/2.7.1/jython-standalone-2.7.1.jar), with the latest snapshot (Build 1392).

2018-10-21 10:20:57.225 [ERROR] [m.espertech.esper.timer.EPLTimerTask] - Timer thread caught unhandled exception: com/espertech/esper/client/time/CurrentTimeEvent
java.lang.NoClassDefFoundError: com/espertech/esper/client/time/CurrentTimeEvent
    at com.espertech.esper.core.service.EPRuntimeImpl.timerCallback(EPRuntimeImpl.java:186) ~[?:?]
    at com.espertech.esper.timer.EPLTimerTask.run(EPLTimerTask.java:57) [?:?]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:?]
    at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [?:?]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [?:?]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [?:?]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]
    at java.lang.Thread.run(Thread.java:748) [?:?]
Caused by: java.lang.ClassNotFoundException: com.espertech.esper.client.time.CurrentTimeEvent
    at org.python.core.SyspathJavaLoader.findClass(SyspathJavaLoader.java:128) ~[?:?]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[?:?]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[?:?]
    ... 9 more
2018-10-21 10:20:57.321 [ERROR] [m.espertech.esper.timer.EPLTimerTask] - Timer thread caught unhandled exception: com/espertech/esper/client/time/CurrentTimeEvent
java.lang.NoClassDefFoundError: com/espertech/esper/client/time/CurrentTimeEvent
    at com.espertech.esper.core.service.EPRuntimeImpl.timerCallback(EPRuntimeImpl.java:186) ~[?:?]
    at com.espertech.esper.timer.EPLTimerTask.run(EPLTimerTask.java:57) [?:?]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:?]
    at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [?:?]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [?:?]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [?:?]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]
    at java.lang.Thread.run(Thread.java:748) [?:?]
5iver commented 5 years ago

This ESH issue may be related... https://github.com/eclipse/smarthome/issues/6392. I have only worked with Jython 2.7.0 in OH. I believe any issues will be within the ESH Automation API, so you may want to followup there, but it makes sense to me to leave this issue open until that is confirmed.

BTW, there is no need to include the Esper module, component script and esper_example.py, unless you are using Esper. These were included in the original repo, and I've considered removing them, but they are good examples. I've also opened #29 to discuss solutions for restructuring the repo for better collaboration.

sillyfrog commented 5 years ago

Thanks for getting back to me. I'll remove everything Esper for the moment.

I'll also see if I can figure out that issue you linked in ESH - a after a quick read I'm not really clear what their issue is, but I'll have a play when I get some more time.

5iver commented 5 years ago

@spacemanspiff2007 is one of the old school JSR223-Jython users... it would be great if we could get him to pop over here too. I've sure he'd appreciate some support on that issue... he brought it up in the forum, and I'd watched the discussion in the Jython repo. I was curious to see how it was going to pan out.

spacemanspiff2007 commented 5 years ago

I've been playing around with 2.7.1 but the only problem I encountered was the interpreter isolation issue. Since I am not using esper I did not research further. But my guess that this is the same problem. The interpreter that loads the esper is different since it is a different file so the other file has no access.

sillyfrog commented 5 years ago

Cheers, do you have more info on the isolation issue? I've seen it now with a few other libraries, so understanding more would be a help.

I'm also not using Esper (so have just got rid of the files), and I think a new layout as per #29 would help with that for others moving forwards.

marcelerkel commented 5 years ago

@sillyfrog the jython installer package (http://central.maven.org/maven2/org/python/jython-installer/2.7.0/jython-installer-2.7.0.jar) also includes pip. I haven't used it myself yet, but just so that you know that this isn't exclusive to 2.7.1.

sillyfrog commented 5 years ago

@marcelerkel Unfortunately when I tried the PIP in v2.7.0, it did not go well, and after some searching, I found this is a common problem that's been addressed in v2.7.1. That said, I have not ended up actually using it (yet), because of the interference that from running within openHAB, not really sure why/how, but it was messing with the zlib library (as part of requests). Thanks!

mjcumming commented 5 years ago

@sillyfrog - have you tried 2.7.1 again? I would like to be able to use pip so that I can use the python requests module.

sillyfrog commented 5 years ago

@mjcumming Here are my notes for getting v2.7.1 going (my plan is to put this on the Wiki when it's enabled): https://gist.github.com/sillyfrog/bc2e8e2546247a616d97078f1e4fa060 However I wanted it for the same reason as you (to install Requests), but it went horribly wrong as it looks like the Java gzip (I think?) module is imported into the same name space, so requests does not work (for my single test case, I have not actually tried very hard as yet to sort this out). But you will at least have a working pip. All of my testing (and production) is done in docker with the v2.4.0 openHAB snapshot (in case it makes a difference). Good luck!

mjcumming commented 5 years ago

I just ran into a namespace collision using my own code... took forever to figure out what was causing the problem. Many of the modules I am interested in using use requests so will have to figure it out.

5iver commented 5 years ago

Many of the modules I am interested in using use requests so will have to figure it out.

requests can't be used in Jython... https://community.openhab.org/t/how-to-setup-jython/53049/119?u=5iver

You could use executeCommandLine to run a Python script using requests directly though.

mjcumming commented 5 years ago

The link to the python FAQ is for version 2.2. Later documents indicate that you can use cpython modules

Jython 2.7 Beta 2 Released (May 2013) Jython 2.7b2 brings us up to language level compatibility with the 2.7 version of CPython. We have focused largely on CPython compatibility, and so this release of Jython can run more pure Python apps then any previous release. Please see the NEWS file for detailed release notes. This is primarily a bugfix release, with numerous improvements, including much improvement on Windows support. Read more on Frank Wierzbickis Weblog PyDev 3.4.1 Available (May 2013) Please visit the PyDev Site for more information. PyDev 3.0 Released (November 2013) From now on, PyDev requires Eclipse 3.7 or 4.3 onwards and Java 7! For older versions, keep using PyDev 2.x. Interpreter is now kept up to date with changes to the interpreter, so, pip-installing packages will automatically update internal caches without requiring a manual step. Fixed issue connecting to shell for code-completion (which could halt the IDE). Please visit the PyDev Site for more information. JyNI 2.7-alpha 2 Released (October 2013) JyNI is a compatibility layer with the goal to enable Jython to use native CPython extensions like NumPy or SciPy. This way we aim to enable scientific Python code to run on Jython. Since Java is rather present in industry, while Python is more present in science, JyNI is an important step to lower the cost of using scientific code in industrial environments. Our philosophy is to integrate JyNI with Jython and CPython extensions as seamless as possible. So JyNI aims to work without any recompilation of Jython or the desired CPython extensions. It neither requires a customized Jython version, nor customized versions of the CPython extensions (of course your JyNI version must meet the platform your CPython extension was build for). Simply put JyNI.jar on the classpath (

mjcumming commented 5 years ago

And requests is specifically mentioned here

https://jaxenter.com/java-python-jython-2-7-beta-3-has-arrived-108027.html

sillyfrog commented 5 years ago

I have found that requests, with Jython v2.7.1 works OK (using a GET as a simple test), if it's not part of OpenHAB. However in the openHAB environment things go bad...

sillyfrog commented 5 years ago

For those interested in getting python requests going it Jython, I have added a note at the end here as to how to make it work :) https://github.com/OH-Jython-Scripters/openhab2-jython/wiki/Using-PIP-in-Docker

J-u-n-o commented 5 years ago

Here a note on Jython 2.7.1. Tried to install the package on my Rasbian PI. I got an installation error on mkdirs (do not have the output): 'File "/opt/jython/Lib/os.py", line 174, in makedirs'. Looks related to http://bugs.jython.org/issue2611. 2.7.0 installed fine. And initial setup went ok for me. Now extend logging... and create sources. ;-)

5iver commented 5 years ago

Not sure if any of you have followed #6392, but I've been running 2.7.1. There have been some errors (detailed in my comment), but I have just updated to 2.7.1.patch2618.jar (I'm using standalone) from https://mvnrepository.com/artifact/org.python/jython-standalone?repo=xebialabs. Hopefully this build will resolve the errors!

This is working, but there is a funky trick to do with ScriptEntensions. I have the scripts and modules updated, but will include this in an upcoming merge to support the ESH migration. Actually, I shouldn't do that. I should merge now and cut a branch, then put the ESH changes in as another release, when the smoke clears.