Skip to content

Commit

Permalink
make sure to close the jep interpreter once we are finished
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanetteclark committed Aug 24, 2023
1 parent c82e512 commit df7ff88
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/main/java/edu/ucsb/nceas/mdqengine/dispatch/Dispatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,15 @@ public Result dispatch(Map<String, Object> variables, String code) throws Script
// harvest all other vars for downstream dispatchers
bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE);

if (engine instanceof SharedInterpreter) {
SharedInterpreter jepInterpreter = (SharedInterpreter) engine;
try {
jepInterpreter.close(); // Call the shutdown() method for SharedInterpreter
} catch (JepException je) {
throw new RuntimeException("Unable to close jep SharedInterpreter");
}
}

return dr;

}
Expand Down Expand Up @@ -354,7 +363,7 @@ public JepScriptEngine() {
* @param script The python script as a string
*
* @throws RuntimeException If an error occurs during script execution.
* @see jep.Jep.SharedInterpreter#exec()
* @see jep.SharedInterpreter#exec()
*
*/
@Override
Expand All @@ -374,7 +383,7 @@ public Object eval(String script) throws RuntimeException {
* @param key The key representing the value to retrieve.
* @return The value associated with the key, if found.
* @throws RuntimeException If an error occurs during value retrieval.
* @see jep.Jep.SharedInterpreter#getValue(String)
* @see jep.SharedInterpreter#getValue(String)
*/
@Override
public Object get(String key) {
Expand All @@ -392,7 +401,7 @@ public Object get(String key) {
* @param key The key to set.
* @param value The value to assign to the key.
* @throws RuntimeException If an error occurs.
* @see jep.Jep.SharedInterpreter#setValue(String)
* @see jep.SharedInterpreter#set(String, Object)
*/
@Override
public void put(String key, Object value) {
Expand Down Expand Up @@ -440,6 +449,10 @@ public Bindings getBindings(int scope) {
return this.globalBindings;
}

public String getEngineName() {
return "python";
}

@Override
public void setBindings(Bindings bindings, int scope) {
throw new UnsupportedOperationException(
Expand Down Expand Up @@ -530,8 +543,7 @@ public List<String> getExtensions() {

@Override
public String getLanguageName() {
throw new UnsupportedOperationException(
"getLanguageName is not implemented for the JepScriptEngineFactory class");
return "python";
}

@Override
Expand Down

0 comments on commit df7ff88

Please sign in to comment.