8

I am using a Python ScriptEngine in my Java application to execute a Python script that imports various other Python scripts.

Once the main script successfully completes and the eval method returns, I set the engine object reference to null and call the garbage collector.

Next I go and edit one of the scripts that was imported by the main script and save it.

Next I run the method to execute the main Python script as before by creating a new ScriptEngine object and calling eval, but when the main script runs it does not pick up the changes to the imported script that I made.

Obviously the imported scripts are being cached somewhere by something (maybe Jython?).

I do not want to call reload in the Python script. There must be a way to tell whatever is doing the caching to flush or clear itself.

Anyone found a solution to this problem? I am using NetBeans 8.0.2, Java 1.8 update 45, and Jython 2.7 on Windows 7. Here is the java code. It doesn't really matter what the python script contains other than import statements.

ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
ScriptEngine engine = scriptEngineManager.getEngineByName("python");
Object result = engine.eval();
engine = null;
System.gc();
Blaine
  • 81
  • 2
  • 1
    Can you create some code in a MCVE (see http://stackoverflow.com/help/mcve) to illustrate the problem? – paisanco Jul 02 '15 at 02:11
  • Added 5 lines of code but I don't think that helps much. – Blaine Jul 02 '15 at 14:40
  • Accoring to http://www.grasshopper3d.com/forum/topics/refreshing-the-python-script-engine add the reload function after your import call for each module that you want dynamically reloaded after it changes. That is after 'import moduleX' on the next line add 'reload(moduleX)'. –  Jul 02 '15 at 17:48
  • As I mentioned in my question, I do not want to add reload to my scripts, nor should I have to in this case of running the script from a ScriptEngine which goes out of scope when it is finished. Also, reload does not work if you use "from blah import *" – Blaine Jul 02 '15 at 22:45

0 Answers0