@Test public void testMultithreadedEval() throws InterruptedException { Assume.assumeTrue(shouldRunMaven); int executionsNum = 5; final String varName = "ABC"; final String varValue = "YYY"; final CountDownLatch latch = new CountDownLatch(executionsNum); for(int i = 0; i < executionsNum; i++) { final int executioId = i; new Thread() { public void run() { try { Map<String, String> sysProps = new HashMap<>(); String value = varValue + executioId; sysProps.put(varName, value); String doubleName = varName + varName; String doubleValue = value + value; Map<String, Serializable> vars = new HashMap<>(); vars.put(doubleName, doubleValue); vars.put(SYSTEM_PROPERTIES_MAP, (Serializable) sysProps); String prepareEnvironmentScript = buildAddFunctionsScript(GET_SP_FUNCTION_DEFINITION); String script = "check_env('" + varName + "', '" + value + "', '" + doubleName + "', '" + doubleValue + "')"; PythonEvaluationResult result = pythonRuntimeService.eval(prepareEnvironmentScript, script, vars); String [] pyResults = ((String) result.getEvalResult()).split(","); assertNotNull(pyResults.length == 2); String [] sysValues = pyResults[0].split(":"); assertNotNull(sysValues.length == 2); assertEquals(sysValues[0], sysValues[1]); String [] globalValues = pyResults[1].split(":"); assertNotNull(globalValues.length == 2); assertEquals(globalValues[0], globalValues[1]); } finally { latch.countDown(); } } }.start(); } latch.await(); }
public PythonEvaluationResult eval(String prepareEnvironmentScript, String expr, Map<String, Serializable> context) { checkValidInterpreter(); try { initInterpreter(); prepareInterpreterContext(context); return new PythonEvaluationResult(eval(prepareEnvironmentScript, expr), getPythonLocals()); } catch (PyException exception) { throw new RuntimeException("Error in running script expression: '" + getTruncatedExpression(expr) + "',\n\tException is: " + handleExceptionSpecialCases(exception.value.toString()), exception); } catch (Exception exception) { throw new RuntimeException("Error in running script expression: '" + getTruncatedExpression(expr) + "',\n\tException is: " + handleExceptionSpecialCases(exception.getMessage()), exception); } }
PythonExecutor implements Executor { public PythonEvaluationResult eval(String prepareEnvironmentScript, String expr, Map<String, Serializable> context) { checkValidInterpreter(); try { initInterpreter(); prepareInterpreterContext(context); return new PythonEvaluationResult(eval(prepareEnvironmentScript, expr), getPythonLocals()); } catch (PyException exception) { throw new RuntimeException("Error in running script expression: '" + getTruncatedExpression(expr) + "',\n\tException is: " + handleExceptionSpecialCases(exception.value.toString()), exception); } catch (Exception exception) { throw new RuntimeException("Error in running script expression: '" + getTruncatedExpression(expr) + "',\n\tException is: " + handleExceptionSpecialCases(exception.getMessage()), exception); } } }
PythonExecutor implements Executor { public PythonEvaluationResult eval(String prepareEnvironmentScript, String expr, Map<String, Serializable> context) { checkValidInterpreter(); try { initInterpreter(); prepareInterpreterContext(context); return new PythonEvaluationResult(eval(prepareEnvironmentScript, expr), getPythonLocals()); } catch (PyException exception) { throw new RuntimeException("Error in running script expression: '" + getTruncatedExpression(expr) + "',\n\tException is: " + handleExceptionSpecialCases(exception.value.toString()), exception); } catch (Exception exception) { throw new RuntimeException("Error in running script expression: '" + getTruncatedExpression(expr) + "',\n\tException is: " + handleExceptionSpecialCases(exception.getMessage()), exception); } } PythonExecutor();  PythonExecutor(Set<String> dependencies); }
PythonExecutor implements Executor { public PythonEvaluationResult eval(String prepareEnvironmentScript, String expr, Map<String, Serializable> context) { checkValidInterpreter(); try { initInterpreter(); prepareInterpreterContext(context); return new PythonEvaluationResult(eval(prepareEnvironmentScript, expr), getPythonLocals()); } catch (PyException exception) { throw new RuntimeException("Error in running script expression: '" + getTruncatedExpression(expr) + "',\n\tException is: " + handleExceptionSpecialCases(exception.value.toString()), exception); } catch (Exception exception) { throw new RuntimeException("Error in running script expression: '" + getTruncatedExpression(expr) + "',\n\tException is: " + handleExceptionSpecialCases(exception.getMessage()), exception); } } PythonExecutor();  PythonExecutor(Set<String> dependencies); PythonExecutionResult exec(String script, Map<String, Serializable> callArguments); PythonEvaluationResult eval(String prepareEnvironmentScript, String expr, Map<String, Serializable> context); @Override void allocate(); @Override void release(); @Override void close(); boolean isClosed(); }
PythonExecutor implements Executor { public PythonEvaluationResult eval(String prepareEnvironmentScript, String expr, Map<String, Serializable> context) { checkValidInterpreter(); try { initInterpreter(); prepareInterpreterContext(context); return new PythonEvaluationResult(eval(prepareEnvironmentScript, expr), getPythonLocals()); } catch (PyException exception) { throw new RuntimeException("Error in running script expression: '" + getTruncatedExpression(expr) + "',\n\tException is: " + handleExceptionSpecialCases(exception.value.toString()), exception); } catch (Exception exception) { throw new RuntimeException("Error in running script expression: '" + getTruncatedExpression(expr) + "',\n\tException is: " + handleExceptionSpecialCases(exception.getMessage()), exception); } } PythonExecutor();  PythonExecutor(Set<String> dependencies); PythonExecutionResult exec(String script, Map<String, Serializable> callArguments); PythonEvaluationResult eval(String prepareEnvironmentScript, String expr, Map<String, Serializable> context); @Override void allocate(); @Override void release(); @Override void close(); boolean isClosed(); static final String THREADED_MODULES_ISSUE; static final int RETRIES_NUMBER_ON_THREADED_ISSUE; static final int MAX_LENGTH; }