ninia / jep

Embed Python in Java
Other
1.3k stars 147 forks source link

Fully shutdown SharedInterpreter / re-load modules #425

Closed surculus12 closed 1 year ago

surculus12 commented 1 year ago

Describe the problem

Currently, changing an imported .py module will not update when re-running the script. This is obviously a desired function of the interpreter. However, I would like to be able to do the following on-command from the user of the application:

  1. Lock/queue the creation of new interpreters. (No problem.)
  2. Shut down all shared interpreters. (No problem.)
  3. Do something that fully clears the state the shared interpreters receive, so that when they are run next time, any modules will be re-imported. (I am unsure how to do this part).

Currently, step 3 requires restarting the java application, which is very sub-optimal when modifying the python code during development, where the full java stack is required to be online to run the python scripts.

surculus12 commented 1 year ago

This problem is solved by running sys.modules.clear() on the interpreter.