@Override public void shutdown() { if (this.interactiveInterpreter != null) { jythonJythonInterpreterFactory.close(this.interactiveInterpreter); } if (currentTask != null) { currentTask.cancel(true); } }
@Override public boolean sendLine(String command, Consumer<String> callback) { if (interactiveInterpreter == null) { try { interactiveInterpreter = jythonJythonInterpreterFactory.createInstance(InteractiveInterpreter.class); interactiveInterpreter.setOut(returnBuffer); interactiveInterpreter.setErr(returnBuffer); } catch (PlayOnLinuxException e) { LOGGER.error(e); } } commandBuffer.append(command); if (command.startsWith("\t") || command.startsWith(" ") || command.trim().endsWith(":")) { commandBuffer.append("\n"); callback.accept(""); return false; } else { String completeCommand = commandBuffer.toString(); commandBuffer.setLength(0); currentTask = executorService.submit( () -> { returnBuffer.getBuffer().setLength(0); try { interactiveInterpreter.exec(completeCommand); callback.accept(returnBuffer.toString()); } catch (PyException e) { LOGGER.debug(e); callback.accept(e.toString()); } }); return true; } }