KotlinInterpreter extends Interpreter { @Override public void cancel(InterpreterContext context) throws InterpreterException { Job<?> runningJob = getRunningJob(context.getParagraphId()); if (runningJob != null) { Map<String, Object> info = runningJob.info(); Object object = info.get("CURRENT_THREAD"); if (object instanceof Thread) { try { Thread t = (Thread) object; t.interrupt(); } catch (Throwable t) { logger.error("Failed to cancel script: " + t, t); } } } } KotlinInterpreter(Properties properties); KotlinReplProperties getKotlinReplProperties(); @Override void open(); @Override void close(); @Override InterpreterResult interpret(String code,
                                     InterpreterContext context); @Override void cancel(InterpreterContext context); @Override FormType getFormType(); @Override int getProgress(InterpreterContext context); @Override List<InterpreterCompletion> completion(String buf, int cursor,
      InterpreterContext interpreterContext); List<KotlinVariableInfo> getVariables(); List<KotlinFunctionInfo> getFunctions();  }
@Test public void testCancel() throws Exception { Thread t = new Thread(() -> { try { InterpreterResult result = interpreter.interpret( "repeat(10000000) { Thread.sleep(100) }", context); assertEquals(ERROR, result.code()); assertEquals("sleep interrupted", result.message().get(0).getData().trim()); } catch (InterpreterException e) { Assert.fail(e.getMessage()); } }); t.start(); Thread.sleep(200); interpreter.cancel(context); }