PY-30285 Code completion in debug console freezes the UI

Set short timeout for UI commands to avoid freeze
This commit is contained in:
Elizaveta Shashkova
2018-07-17 12:51:15 +03:00
parent c25e0b5778
commit 424d3be0a4
@@ -36,6 +36,7 @@ import static com.jetbrains.python.debugger.pydev.transport.BaseDebuggerTranspor
public class RemoteDebugger implements ProcessDebugger {
private static final int RESPONSE_TIMEOUT = 60000;
private static final int SHORT_TIMEOUT = 2000;
private static final Logger LOG = Logger.getInstance("#com.jetbrains.python.pydev.remote.RemoteDebugger");
@@ -339,8 +340,7 @@ public class RemoteDebugger implements ProcessDebugger {
return myDebuggerTransport.isConnecting() || myDebuggerTransport.isConnected();
}
@Override
public void execute(@NotNull final AbstractCommand command) {
public void execute(@NotNull final AbstractCommand command, int responseTimeout) {
CountDownLatch myLatch = new CountDownLatch(1);
ApplicationManager.getApplication().executeOnPooledThread(() -> {
if (command instanceof ResumeOrStepCommand) {
@@ -361,7 +361,7 @@ public class RemoteDebugger implements ProcessDebugger {
if (command.isResponseExpected()) {
// Note: do not wait for result from UI thread
try {
myLatch.await(RESPONSE_TIMEOUT, TimeUnit.MILLISECONDS);
myLatch.await(responseTimeout, TimeUnit.MILLISECONDS);
}
catch (InterruptedException e) {
// restore interrupted flag
@@ -372,6 +372,11 @@ public class RemoteDebugger implements ProcessDebugger {
}
}
@Override
public void execute(@NotNull final AbstractCommand command) {
execute(command, RESPONSE_TIMEOUT);
}
boolean sendFrame(final ProtocolFrame frame) {
return myDebuggerTransport.sendFrame(frame);
}
@@ -674,14 +679,14 @@ public class RemoteDebugger implements ProcessDebugger {
@Override
public List<PydevCompletionVariant> getCompletions(String threadId, String frameId, String prefix) {
final GetCompletionsCommand command = new GetCompletionsCommand(this, threadId, frameId, prefix);
execute(command);
execute(command, SHORT_TIMEOUT);
return command.getCompletions();
}
@Override
public String getDescription(String threadId, String frameId, String cmd) {
final GetDescriptionCommand command = new GetDescriptionCommand(this, threadId, frameId, cmd);
execute(command);
execute(command, SHORT_TIMEOUT);
return command.getResult();
}