Strange issue with PYTHONPATH in NKEE 6.2.1

Poster Content
nk4um Administrator
Posts: 605
June 19, 2018 22:16

Hi, a fix is now available in apposite. Let me know how you get on.

Like · Post Reply
nk4um Administrator
Posts: 605
June 17, 2018 14:08

Hi Gary, i found in bug in our python wrapper endpoint. It seems that in certain cases modules are loaded at runtime again by Jython. In that case the last request context used by compiler would get used. So in your exact scenario module A was trying load it's python packages using module Bs request context - and hence not finding them.

I'll get the update out to you in Apposite ASAP. Thanks for your patience, it's a long time since I looked at python.

Like · Post Reply
nk4um Administrator
Posts: 605
June 14, 2018 15:28

Hi Gary, thanks for reporting this. I'll take a look.

Like · Post Reply
nk4um User
Posts: 7
June 14, 2018 14:37Strange issue with PYTHONPATH in NKEE 6.2.1

Hi all,

I'm experiencing a real head-scratcher involving the resolution of Python library modules once they've been cached.

I have a couple of modules in my NKEE 6.2.1 deployment that are using Python. Both of them have an etc/PYTHONPATH resource. The first module (let's call it "module-A") includes some additional Python packages in a directory named "python-modules". The PYTHONPATH resource for module-A looks like this:

res:/library/python/2.7.0/
res:/python-modules/

The second module (which we'll call module-B) does not use any additional Python packages, and it's PYTHONPATH file looks like this:

res:/library/python/2.7.0/

When I SOURCE my endpoint on module-A *for the first time*, NK finds all of the necessary Python imports via PYTHONPATH (standard Python packages, plus the ones I have under /python-modules, and completes successfully. I then, subsequently, SOURCE my endpoint on module-B (note: module-A and module-B do not import each other), and module-B completes successfully as well.

Here's where it gets weird. If I now SOURCE module-A's endpoint a second time, packages under res:/python-modules are no longer found, and my Python scripts in the module throw runtime ImportError exceptions, like this:

<ex>
    <id>SubrequestException</id>
    <space>Lang / Python (private)</space>
    <endpoint>PythonRuntime</endpoint>
    <logicalEndpoint>PythonRuntime</logicalEndpoint>
    <ex>
        <id>Python Runtime Exception</id>
        <message>
Traceback (most recent call last): File "res:/scripts/bi-second-pw.py", line 3, in <module> ImportError: No module named rsa
</message>
    </ex>
</ex>

When this occurs, I can go into the cache viewer and find the representations for the Python packages that cause the ImportError. And if I clear the cache, module-A works again (until module-B runs).

For the life of me, I cannot figure out what sort of weird interplay is going on here...any help or pointers as to where to start looking would be most appreciated.

Thanks,

--Gary

Like · Post Reply