From df7ff880bf842e5306a4cfa462d16427743ed6ab Mon Sep 17 00:00:00 2001 From: Jeanette Clark Date: Thu, 24 Aug 2023 13:14:44 -0700 Subject: [PATCH] make sure to close the jep interpreter once we are finished --- .../nceas/mdqengine/dispatch/Dispatcher.java | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/main/java/edu/ucsb/nceas/mdqengine/dispatch/Dispatcher.java b/src/main/java/edu/ucsb/nceas/mdqengine/dispatch/Dispatcher.java index e253341f..3f15a9f1 100644 --- a/src/main/java/edu/ucsb/nceas/mdqengine/dispatch/Dispatcher.java +++ b/src/main/java/edu/ucsb/nceas/mdqengine/dispatch/Dispatcher.java @@ -179,6 +179,15 @@ public Result dispatch(Map 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; } @@ -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 @@ -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) { @@ -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) { @@ -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( @@ -530,8 +543,7 @@ public List getExtensions() { @Override public String getLanguageName() { - throw new UnsupportedOperationException( - "getLanguageName is not implemented for the JepScriptEngineFactory class"); + return "python"; } @Override