private XDebugSession connectToDebugger() throws ExecutionException {
    final ServerSocket serverSocket = PythonCommandLineState.createServerSocket();

    final XDebugSession session =
        XDebuggerManager.getInstance(getProject())
            .startSessionAndShowTab(
                "Python Console Debugger",
                PythonIcons.Python.Python,
                null,
                true,
                new XDebugProcessStarter() {
                  @NotNull
                  public XDebugProcess start(@NotNull final XDebugSession session) {
                    PythonDebugLanguageConsoleView debugConsoleView =
                        new PythonDebugLanguageConsoleView(getProject(), mySdk);

                    PyConsoleDebugProcessHandler consoleDebugProcessHandler =
                        new PyConsoleDebugProcessHandler(myProcessHandler);

                    PyConsoleDebugProcess consoleDebugProcess =
                        new PyConsoleDebugProcess(
                            session, serverSocket, debugConsoleView, consoleDebugProcessHandler);

                    PythonDebugConsoleCommunication communication =
                        PyDebugRunner.initDebugConsoleView(
                            getProject(),
                            consoleDebugProcess,
                            debugConsoleView,
                            consoleDebugProcessHandler);

                    myPydevConsoleCommunication.setDebugCommunication(communication);
                    debugConsoleView.attachToProcess(consoleDebugProcessHandler);

                    consoleDebugProcess.waitForNextConnection();

                    try {
                      consoleDebugProcess.connect(myPydevConsoleCommunication);
                    } catch (Exception e) {
                      LOG.error(e); // TODO
                    }

                    myProcessHandler.notifyTextAvailable(
                        "\nDebugger connected.\n", ProcessOutputTypes.STDERR);

                    return consoleDebugProcess;
                  }
                });

    return session;
  }