private XDebugSession launchRemoteDebugServer() throws ExecutionException {
    final ServerSocket serverSocket;
    try {
      //noinspection SocketOpenedButNotSafelyClosed
      serverSocket = new ServerSocket(0);
    }
    catch (IOException e) {
      throw new ExecutionException(PyBundle.message("debugger.attach.to.process.failed.to.find.free.socket.port"), e);
    }


    PyAttachToProcessCommandLineState state = PyAttachToProcessCommandLineState.create(myProject, mySdk, serverSocket.getLocalPort(), myPid);

    final ExecutionResult result = state.execute(state.getEnvironment().getExecutor(), this);

    //start remote debug server
    return XDebuggerManager.getInstance(myProject).
      startSessionAndShowTab(String.valueOf(myPid), null, new XDebugProcessStarter() {
        @Override
        public @NotNull XDebugProcess start(final @NotNull XDebugSession session) {
          PyRemoteDebugProcess pyDebugProcess =
            new PyRemoteDebugProcess(session, serverSocket, result.getExecutionConsole(),
                                     result.getProcessHandler(), "") {
              @Override
              protected void printConsoleInfo() {
              }

              @Override
              public int getConnectTimeout() {
                return getInt("python.debugger.attach.timeout");
              }

              @Override
              protected void detachDebuggedProcess() {
                handleStop();
              }

              @Override
              protected String getConnectionMessage() {
                return PyBundle.message("python.debugger.attaching.to.process.with.pid", myPid);
              }

              @Override
              protected String getConnectionTitle() {
                return PyBundle.message("python.debugger.attaching");
              }
            };
          pyDebugProcess.setPositionConverter(new PyLocalPositionConverter());


          createConsoleCommunicationAndSetupActions(myProject, result, pyDebugProcess, session);

          return pyDebugProcess;
        }
      });
  }
private XDebugSession launchRemoteDebugServer()