Message12082

Author jeff.allen
Recipients jeff.allen, spaceman_spiff, stefan.richthofer
Date 2018-08-11.17:04:07
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1534007049.19.0.56676864532.issue2700@psf.upfronthosting.co.za>
In-reply-to
Content
Ah, I wondered what ModuleB was for. If we are standardising on uppercase "TestModule", then your text for test_file is still wrong.

Resorting to bash for a moment, I can show you without mistakes that I have exactly this:

$ tail -n +1 -- Module*.py TestModule/*.py
==> ModuleA.py <==
import TestModule

==> ModuleB.py <==
import ModuleA
import TestModule

==> TestModule/__init__.py <==
import test_file

==> TestModule/test_file.py <==
import TestModule
print( 'TESTPROP: {}'.format(hasattr(TestModule, 'TESTPROP')))
TestModule.TESTPROP = 'TEST'
print( 'TESTPROP: {}'.format(hasattr(TestModule, 'TESTPROP')))

Now in a PowerShell I get:
PS 271-sa> java -Xmx512m -Xss2560k -cp "C:\Jython\2.7.1-sa\jython-standalone-2.7.1.jar" org.python.util.jython ModuleB.py
TESTPROP: 0
TESTPROP: 1
PS 271-sa>

My setup is:
PS 271-sa> java -Xmx512m -Xss2560k -cp "C:\Jython\2.7.1-sa\jython-standalone-2.7.1.jar" org.python.util.jython
Jython 2.7.1 (default:0df7adb1b397, Jun 30 2017, 19:02:43)
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.7.0_60

But on a quick check I get the same behaviour with Java 8 and 9.

I'm puzzled by "In my openhab instance ...". If you try your own example at the prompt, do you not get the same as I? And if it's different in some other environment ... well, it's an integration problem so it could be either party. I would be nice to have them work together. But I think we're barking up the wrong tree doing this at the Windows prompt.

The JSR-223 wrapper can make a material difference (usually in the area of console i/o). Maybe openhab creates and disposes of interpreters, which is somewhat like reloading sys and sys.modules. At the Jython prompt I can do this:

>>> from javax.script import ScriptEngineManager as SEM
>>> sem = SEM()
>>> se = sem.getEngineByName('jython')
>>> se.eval("import sys; sys.path[:0]=['']; print sys.path")
['', 'C:\\Jython\\2.7.1-sa\\Lib', 'C:\\Jython\\2.7.1-sa\\jython-standalone-2.7.1.jar\\Lib', '__classpath__', '__pyclasspath__/', 'C:\\Users\\Jeff\\.local\\lib\\jython2.7\\site-packages']
>>> se.eval("import ModuleB")
TESTPROP: 0
TESTPROP: 1
>>> se.eval("import ModuleB")
>>>

The second import has no effect as you'd expect. But create yourself another interpreter (se2 = ...), and you have to do all that afresh, and you get the output again.
History
Date User Action Args
2018-08-11 17:04:09jeff.allensetmessageid: <1534007049.19.0.56676864532.issue2700@psf.upfronthosting.co.za>
2018-08-11 17:04:09jeff.allensetrecipients: + jeff.allen, stefan.richthofer, spaceman_spiff
2018-08-11 17:04:09jeff.allenlinkissue2700 messages
2018-08-11 17:04:07jeff.allencreate