ninia / jep

Embed Python in Java
Other
1.31k stars 149 forks source link

Data update not being recognized in SharedInterpreter #492

Closed dlnorgaard closed 1 year ago

dlnorgaard commented 1 year ago

I am executing a function in a file that imports and uses data from another file. This data in the other file is periodically updated, but is not reflected in the function being called after the data changes. This only happens in the SharedInterpreter, and not in SubInterpreter. It is as if the import of the variable from the file isn't being called again in the SharedIntepreter. Unfortunately, if I use SubInterpreter I can't make simultaneous Python calls since I have to wait for one to finish before another SubInterpreter can be opened. Is there some way to clear out stuff remaining in SharedInterpreter?

bsteffensmeier commented 1 year ago

You are correct that python will cache any imported modules and will not reload them when you import them again later. Jep SharedInterpreters share this cache so it makes sense the modules are not reloaded in new SharedInterpreters. If you need to reload a module it looks like importlib.reload should be able to do what you need.

dlnorgaard commented 1 year ago

I'm having some difficulty getting that to work but will report back once I figure it out.

dlnorgaard commented 1 year ago

I got it to work for one situation but not the other. I may be doing imports in multiple places and perhaps some are not getting updated. In many cases I have been doing from mymodule import xxx and I think I need to do import mymodule. Although this means I have to prefix stuff with module name which I wanted to avoid since the generated code is already long. I'm open to some other suggestions....

dlnorgaard commented 1 year ago

I made some progress, but now realized I have imports of the same name but from different directories that complicates things. I think the importlib.reload does address the original issue so I am going to close this ticket. Thanks.