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()));
}
});
}
}
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);
}
}
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);
}
}
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));
}
Aggregations