@Override
  public void waitForConnect() throws IOException {
    if (myState != State.INIT) {
      throw new IllegalStateException(
        "Inappropriate state of Python debugger for connecting to Python debugger: " + myState + "; " + State.INIT + " is expected");
    }

    boolean connected = false;
    try {
      Socket clientSocket = new Socket();
      clientSocket.setSoTimeout(HANDSHAKE_TIMEOUT_IN_MILLIS);
      clientSocket.connect(new InetSocketAddress(myHost, myPort), CONNECTION_TIMEOUT_IN_MILLIS);

      synchronized (mySocketObject) {
        mySocket = clientSocket;
        myState = State.CONNECTED;
      }

      DebuggerReader debuggerReader;
      try {
        myDebuggerReader = debuggerReader = new DebuggerReader(myDebugger, clientSocket.getInputStream());
      }
      catch (IOException e) {
        LOG.debug("Failed to create debugger reader", e);
        throw e;
      }

      try {
        myDebugger.handshake();

        debuggerReader.connectionApproved();
        connected = true;

        // after successful connection turn back original timeout
        clientSocket.setSoTimeout(0);
      }
      catch (PyDebuggerException e) {
        LOG.debug(String.format("[%d] Handshake failed", hashCode()));
      }
      finally {
        if (!connected) {
          debuggerReader.close();
        }
      }
    }
    catch (ConnectException | SocketTimeoutException e) {
      myState = State.DISCONNECTED;
      throw new IOException("Failed to connect to debugger script", e);
    }

    if (!connected) {
      myState = State.DISCONNECTED;
      throw new IOException("Failed to connect to debugger script");
    }

    myState = State.APPROVED;
    LOG.debug(String.format("[%d] Connected to debugger script", hashCode()));
  }
@Override
  public void waitForConnect()