Search in sources :

Example 1 with PyDebuggerException

use of com.jetbrains.python.debugger.PyDebuggerException in project intellij-community by JetBrains.

the class PythonDebugConsoleCommunication method execInterpreter.

public void execInterpreter(ConsoleCodeFragment code, final Function<InterpreterResponse, Object> callback) {
    if (waitingForInput) {
        final OutputStream processInput = myDebugProcess.getProcessHandler().getProcessInput();
        if (processInput != null) {
            try {
                final Charset defaultCharset = EncodingProjectManager.getInstance(myDebugProcess.getProject()).getDefaultCharset();
                processInput.write((code.getText()).getBytes(defaultCharset));
                processInput.flush();
            } catch (IOException e) {
                LOG.error(e.getMessage());
            }
        }
        myNeedsMore = false;
        waitingForInput = false;
        notifyCommandExecuted(waitingForInput);
    } else {
        exec(new ConsoleCodeFragment(code.getText(), false), new PyDebugCallback<Pair<String, Boolean>>() {

            @Override
            public void ok(Pair<String, Boolean> executed) {
                boolean more = executed.second;
                myNeedsMore = more;
                notifyCommandExecuted(more);
                callback.fun(new InterpreterResponse(more, isWaitingForInput()));
            }

            @Override
            public void error(PyDebuggerException exception) {
                myNeedsMore = false;
                notifyCommandExecuted(false);
                callback.fun(new InterpreterResponse(false, isWaitingForInput()));
            }
        });
    }
}
Also used : OutputStream(java.io.OutputStream) InterpreterResponse(com.jetbrains.python.console.pydev.InterpreterResponse) Charset(java.nio.charset.Charset) IOException(java.io.IOException) PyDebuggerException(com.jetbrains.python.debugger.PyDebuggerException) Pair(com.intellij.openapi.util.Pair)

Example 2 with PyDebuggerException

use of com.jetbrains.python.debugger.PyDebuggerException in project intellij-community by JetBrains.

the class PyDataViewerPanel method apply.

public void apply(@NotNull PyDebugValue debugValue) {
    myErrorLabel.setVisible(false);
    String type = debugValue.getType();
    DataViewStrategy strategy = DataViewStrategy.getStrategy(type);
    if (strategy == null) {
        setError(type + " is not supported");
        return;
    }
    try {
        ArrayChunk arrayChunk = debugValue.getFrameAccessor().getArrayItems(debugValue, 0, 0, -1, -1, getFormat());
        updateUI(arrayChunk, debugValue, strategy);
    } catch (PyDebuggerException e) {
        LOG.error(e);
    }
}
Also used : ArrayChunk(com.jetbrains.python.debugger.ArrayChunk) PyDebuggerException(com.jetbrains.python.debugger.PyDebuggerException)

Example 3 with PyDebuggerException

use of com.jetbrains.python.debugger.PyDebuggerException in project intellij-community by JetBrains.

the class GetDescriptionCommand method processResponse.

@Override
protected void processResponse(ProtocolFrame response) throws PyDebuggerException {
    super.processResponse(response);
    try {
        PyDebugValue pyDebugValue = ProtocolParser.parseValue(response.getPayload(), getDebugger().getDebugProcess());
        result = pyDebugValue.getValue();
    } catch (Exception e) {
        throw new PyDebuggerException("cant obtain completions", e);
    }
}
Also used : PyDebugValue(com.jetbrains.python.debugger.PyDebugValue) PyDebuggerException(com.jetbrains.python.debugger.PyDebuggerException) PyDebuggerException(com.jetbrains.python.debugger.PyDebuggerException)

Example 4 with PyDebuggerException

use of com.jetbrains.python.debugger.PyDebuggerException in project intellij-community by JetBrains.

the class ClientModeDebuggerTransport method waitForConnect.

@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");
    }
    synchronized (mySocketObject) {
        if (mySocket != null) {
            try {
                mySocket.close();
            } catch (IOException e) {
                LOG.debug("Failed to close previously opened socket", e);
            } finally {
                mySocket = null;
            }
        }
    }
    int i = 0;
    boolean connected = false;
    while (!connected && i < MAX_CONNECTION_TRIES) {
        i++;
        int attempt = i;
        LOG.debug(String.format("[%d] Trying to connect: #%d attempt", hashCode(), attempt));
        try {
            Socket clientSocket = new Socket();
            clientSocket.setSoTimeout(0);
            clientSocket.connect(new InetSocketAddress(myHost, myPort));
            synchronized (mySocketObject) {
                mySocket = clientSocket;
                myState = State.CONNECTED;
            }
            try {
                InputStream stream;
                synchronized (mySocketObject) {
                    stream = mySocket.getInputStream();
                }
                myDebuggerReader = new DebuggerReader(myDebugger, stream);
            } catch (IOException e) {
                LOG.debug("Failed to create debugger reader", e);
                throw e;
            }
            CountDownLatch beforeHandshake = new CountDownLatch(1);
            Future<Boolean> future = ApplicationManager.getApplication().executeOnPooledThread(() -> {
                beforeHandshake.countDown();
                try {
                    myDebugger.handshake();
                    myDebuggerReader.connectionApproved();
                    return true;
                } catch (PyDebuggerException e) {
                    LOG.debug(String.format("[%d] Handshake failed: #%d attempt", hashCode(), attempt));
                    return false;
                }
            });
            try {
                beforeHandshake.await();
                connected = future.get(CHECK_CONNECTION_APPROVED_DELAY, TimeUnit.MILLISECONDS);
            } catch (InterruptedException e) {
                LOG.debug(String.format("[%d] Waiting for handshake interrupted: #%d attempt", hashCode(), attempt), e);
                myDebuggerReader.close();
                throw new IOException("Waiting for subprocess interrupted", e);
            } catch (ExecutionException e) {
                LOG.debug(String.format("[%d] Execution exception occurred: #%d attempt", hashCode(), attempt), e);
            } catch (TimeoutException e) {
                LOG.debug(String.format("[%d] Timeout: #%d attempt", hashCode(), attempt), e);
                future.cancel(true);
            }
            if (!connected) {
                myDebuggerReader.close();
                try {
                    Thread.sleep(SLEEP_TIME_BETWEEN_CONNECTION_TRIES);
                } catch (InterruptedException e) {
                    throw new IOException(e);
                }
            }
        } catch (ConnectException e) {
            if (i < MAX_CONNECTION_TRIES) {
                try {
                    Thread.sleep(SLEEP_TIME_BETWEEN_CONNECTION_TRIES);
                } catch (InterruptedException e1) {
                    throw new IOException(e1);
                }
            }
        }
    }
    if (!connected) {
        myState = State.DISCONNECTED;
        throw new IOException("Failed to connect to debugging script");
    }
    myState = State.APPROVED;
    LOG.debug(String.format("[%d] Connected to Python debugger script on #%d attempt", hashCode(), i));
}
Also used : InetSocketAddress(java.net.InetSocketAddress) InputStream(java.io.InputStream) IOException(java.io.IOException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Socket(java.net.Socket) PyDebuggerException(com.jetbrains.python.debugger.PyDebuggerException) ConnectException(java.net.ConnectException)

Aggregations

PyDebuggerException (com.jetbrains.python.debugger.PyDebuggerException)4 IOException (java.io.IOException)2 Pair (com.intellij.openapi.util.Pair)1 InterpreterResponse (com.jetbrains.python.console.pydev.InterpreterResponse)1 ArrayChunk (com.jetbrains.python.debugger.ArrayChunk)1 PyDebugValue (com.jetbrains.python.debugger.PyDebugValue)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 ConnectException (java.net.ConnectException)1 InetSocketAddress (java.net.InetSocketAddress)1 Socket (java.net.Socket)1 Charset (java.nio.charset.Charset)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1