@Override
 protected PythonConsoleView createConsoleView() {
   PythonConsoleView consoleView = new PythonConsoleView(getProject(), getConsoleTitle(), mySdk);
   myPydevConsoleCommunication.setConsoleFile(consoleView.getConsoleVirtualFile());
   consoleView.addMessageFilter(new PythonTracebackFilter(getProject()));
   return consoleView;
 }
 private boolean handshake() {
   boolean res;
   long started = System.currentTimeMillis();
   do {
     try {
       res = myPydevConsoleCommunication.handshake();
     } catch (XmlRpcException ignored) {
       res = false;
     }
     if (res) {
       break;
     } else {
       long now = System.currentTimeMillis();
       if (now - started > APPROPRIATE_TO_WAIT) {
         break;
       } else {
         try {
           Thread.sleep(100);
         } catch (InterruptedException ignored) {
         }
       }
     }
   } while (true);
   return res;
 }
 protected List<String> getCompoundValueChildren(PyDebugValue value) throws PyDebuggerException {
   XValueChildrenList list = myCommunication.loadVariable(value);
   List<String> result = Lists.newArrayList();
   for (int i = 0; i < list.size(); i++) {
     result.add(((PyDebugValue) list.getValue(i)).getValue());
   }
   return result;
 }
  protected PyDebugValue getValue(String varName) throws PyDebuggerException {
    XValueChildrenList l = myCommunication.loadFrame();

    if (l == null) {
      return null;
    }
    for (int i = 0; i < l.size(); i++) {
      String name = l.getName(i);
      if (varName.equals(name)) {
        return (PyDebugValue) l.getValue(i);
      }
    }

    return null;
  }
 private void closeCommunication() {
   if (!myProcessHandler.isProcessTerminated()) {
     myPydevConsoleCommunication.close();
   }
 }
 protected void interrupt() {
   myCommunication.interrupt();
 }
 protected void setValue(String varName, String value) throws PyDebuggerException {
   PyDebugValue val = getValue(varName);
   myCommunication.changeVariable(val, value);
 }
  @Override
  public void runTestOn(final String sdkHome) throws Exception {
    final Project project = getProject();

    final Sdk sdk = createTempSdk(sdkHome, SdkCreationType.EMPTY_SDK);

    setProcessCanTerminate(false);

    PydevConsoleRunner consoleRunner =
        new PydevConsoleRunner(
            project,
            sdk,
            PyConsoleType.PYTHON,
            myFixture.getTempDirPath(),
            Maps.<String, String>newHashMap(),
            PyConsoleOptions.getInstance(project).getPythonConsoleSettings(),
            new String[] {}) {
          @Override
          protected void showConsole(
              Executor defaultExecutor, @NotNull RunContentDescriptor contentDescriptor) {
            myContentDescriptorRef.set(contentDescriptor);
            super.showConsole(defaultExecutor, contentDescriptor);
          }
        };

    before();

    myConsoleInitSemaphore = new Semaphore(0);

    consoleRunner.addConsoleListener(
        new PydevConsoleRunner.ConsoleListener() {
          @Override
          public void handleConsoleInitialized(LanguageConsoleView consoleView) {
            myConsoleInitSemaphore.release();
          }
        });

    consoleRunner.run();

    waitFor(myConsoleInitSemaphore);

    myCommandSemaphore = new Semaphore(1);

    myConsoleView = consoleRunner.getConsoleView();
    myProcessHandler = (PyConsoleProcessHandler) consoleRunner.getProcessHandler();

    myExecuteHandler =
        (PydevConsoleExecuteActionHandler) consoleRunner.getConsoleExecuteActionHandler();

    myCommunication = consoleRunner.getPydevConsoleCommunication();

    myCommunication.addCommunicationListener(
        new ConsoleCommunicationListener() {
          @Override
          public void commandExecuted(boolean more) {
            myCommandSemaphore.release();
          }

          @Override
          public void inputRequested() {}
        });

    myProcessHandler.addProcessListener(
        new ProcessAdapter() {
          @Override
          public void processTerminated(ProcessEvent event) {
            if (event.getExitCode() != 0 && !myProcessCanTerminate) {
              Assert.fail("Process terminated unexpectedly\n" + output());
            }
          }
        });

    OutputPrinter myOutputPrinter = null;
    if (shouldPrintOutput) {
      myOutputPrinter = new OutputPrinter();
      myOutputPrinter.start();
    }

    waitForOutput("PyDev console");

    try {
      testing();
      after();
    } finally {
      setProcessCanTerminate(true);

      if (myOutputPrinter != null) {
        myOutputPrinter.stop();
      }

      disposeConsole();
    }
  }