How to get Python ScriptEngine to clear the cache of imported modules?

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

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

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

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

Obviously, the imported scripts are cached somewhere (maybe Jython?).

I do not want to trigger a reboot in a Python script. There must be a way to tell what caching does to cleanse or cleanse itself.

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

ScriptEngineManager scriptEngineManager = new ScriptEngineManager(); ScriptEngine engine = scriptEngineManager.getEngineByName("python"); Object result = engine.eval(); engine = null; System.gc(); 
+6
source share

All Articles