diff --git a/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/bindings/scripts/ScriptEvaluator.java b/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/bindings/scripts/ScriptEvaluator.java index 929c77057..5f1e7e903 100644 --- a/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/bindings/scripts/ScriptEvaluator.java +++ b/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/bindings/scripts/ScriptEvaluator.java @@ -16,6 +16,7 @@ import io.cloudslang.lang.entities.bindings.values.ValueFactory; import io.cloudslang.lang.runtime.services.ScriptsService; import io.cloudslang.runtime.api.python.PythonEvaluationResult; +import io.cloudslang.runtime.api.python.PythonExecutorLifecycleManagerService; import io.cloudslang.runtime.api.python.PythonRuntimeService; import io.cloudslang.runtime.api.python.enums.PythonStrategy; import io.cloudslang.runtime.impl.python.external.ExternalPythonScriptException; @@ -70,6 +71,9 @@ public class ScriptEvaluator extends ScriptProcessor { @Autowired private ScriptsService scriptsService; + @Autowired + private PythonExecutorLifecycleManagerService pythonExecutorLifecycleManagerService; + public Value evalExpr(String expr, Map context, Set systemProperties, Set functionDependencies) { try { @@ -148,13 +152,18 @@ private Value doEvaluateExpressionPythonExecutor(String expr, } PythonEvaluationResult result; - try { - result = pythonExecutorService.eval( - buildAddFunctionsScriptForExternalPython(functionDependencies), expr, pythonContext); - } catch (ExternalPythonScriptException exception) { - if (logger.isDebugEnabled()) { - logger.warn("Could not evaluate expressions on python executor, retrying with python"); + if (pythonExecutorLifecycleManagerService.isAlive()) { + try { + result = pythonExecutorService.eval( + buildAddFunctionsScriptForExternalPython(functionDependencies), expr, pythonContext); + } catch (ExternalPythonScriptException exception) { + if (logger.isDebugEnabled()) { + logger.warn("Could not evaluate expressions on python executor, retrying with python"); + } + result = pythonRuntimeService.eval( + buildAddFunctionsScriptForExternalPython(functionDependencies), expr, pythonContext); } + } else { result = pythonRuntimeService.eval( buildAddFunctionsScriptForExternalPython(functionDependencies), expr, pythonContext); }