diff --git a/python/build/pycharm_build.gant b/python/build/pycharm_build.gant index fca2805e8fa4..0011f8e51b12 100644 --- a/python/build/pycharm_build.gant +++ b/python/build/pycharm_build.gant @@ -55,7 +55,7 @@ private List platformImplementationModules() { } private List platformApiModules() { - return ["platform-api", "lvcs-api", "lang-api", "vcs-api", "usageView", "xdebugger-api", "xml-openapi", "dom-openapi"] + return ["platform-api", "lvcs-api", "lang-api", "vcs-api", "usageView", "xdebugger-api", "xml-openapi", "dom-openapi", "webide-api"] } def includeFile(String filepath) { diff --git a/python/pydevSrc/com/jetbrains/python/console/pydev/PydevXmlRpcClient.java b/python/pydevSrc/com/jetbrains/python/console/pydev/PydevXmlRpcClient.java index 6e87fcd8b3e2..b5e4ab2df6b5 100644 --- a/python/pydevSrc/com/jetbrains/python/console/pydev/PydevXmlRpcClient.java +++ b/python/pydevSrc/com/jetbrains/python/console/pydev/PydevXmlRpcClient.java @@ -44,6 +44,8 @@ public class PydevXmlRpcClient implements IPydevXmlRpcClient { */ private static final Logger LOG = Logger.getInstance(PydevXmlRpcClient.class.getName()); + private static final long TIME_LIMIT = 5000; + /** * Constructor (see fields description) @@ -79,8 +81,9 @@ public class PydevXmlRpcClient implements IPydevXmlRpcClient { } }); + long started = System.currentTimeMillis(); //busy loop waiting for the answer (or having the console die). - while (result[0] == null) { + while (result[0] == null && System.currentTimeMillis() - started < TIME_LIMIT) { try { if (process != null) { final String errStream = stdErrReader.getContents(); @@ -113,6 +116,9 @@ public class PydevXmlRpcClient implements IPydevXmlRpcClient { } } } + if (result[0] == null) { + throw new XmlRpcException(-1, "Timeout while connecting to server"); + } return result[0]; } } diff --git a/python/python.iml b/python/python.iml index e9b3e2fb1690..57624ffc30b3 100644 --- a/python/python.iml +++ b/python/python.iml @@ -32,7 +32,7 @@ - + diff --git a/python/src/com/jetbrains/python/console/PyConsoleProcessHandler.java b/python/src/com/jetbrains/python/console/PyConsoleProcessHandler.java index 6a686a71dabe..6a6b29d23039 100644 --- a/python/src/com/jetbrains/python/console/PyConsoleProcessHandler.java +++ b/python/src/com/jetbrains/python/console/PyConsoleProcessHandler.java @@ -1,9 +1,9 @@ package com.jetbrains.python.console; import com.intellij.execution.console.LanguageConsoleImpl; -import com.intellij.execution.process.ColoredProcessHandler; import com.intellij.openapi.util.Key; import com.intellij.openapi.util.text.StringUtil; +import com.jetbrains.python.console.pydev.PydevConsoleCommunication; import com.jetbrains.python.run.PythonProcessHandler; import java.nio.charset.Charset; @@ -13,13 +13,15 @@ import java.nio.charset.Charset; */ public class PyConsoleProcessHandler extends PythonProcessHandler { private final LanguageConsoleImpl myLanguageConsole; + private final PydevConsoleCommunication myPydevConsoleCommunication; public PyConsoleProcessHandler(final Process process, final LanguageConsoleImpl languageConsole, - final String commandLine, + PydevConsoleCommunication pydevConsoleCommunication, final String commandLine, final Charset charset) { super(process, commandLine, charset); myLanguageConsole = languageConsole; + myPydevConsoleCommunication = pydevConsoleCommunication; } @@ -42,18 +44,19 @@ public class PyConsoleProcessHandler extends PythonProcessHandler { for (String prompt : PROMPTS) { if (string.startsWith(prompt)) { // Process multi prompts here - if (prompt != PyConsoleHighlightingUtil.HELP_PROMPT){ + if (prompt != PyConsoleHighlightingUtil.HELP_PROMPT) { final StringBuilder builder = new StringBuilder(); builder.append(prompt).append(prompt); - while (string.startsWith(builder.toString())){ + while (string.startsWith(builder.toString())) { builder.append(prompt); } final String multiPrompt = builder.toString().substring(prompt.length()); - if (prompt == PyConsoleHighlightingUtil.INDENT_PROMPT){ + if (prompt == PyConsoleHighlightingUtil.INDENT_PROMPT) { prompt = multiPrompt; } string = string.substring(multiPrompt.length()); - } else { + } + else { string = string.substring(prompt.length()); } @@ -68,4 +71,30 @@ public class PyConsoleProcessHandler extends PythonProcessHandler { } return string; } + + @Override + protected void destroyProcessImpl() { + doCloseCommunication(); + super.destroyProcessImpl(); + } + + @Override + protected void detachProcessImpl() { + doCloseCommunication(); + super.detachProcessImpl(); + } + + private void doCloseCommunication() { + if (myPydevConsoleCommunication != null) { + try { + myPydevConsoleCommunication.close(); + // waiting for REPL communication before destroying process handler + Thread.sleep(300); + } + catch (Exception e1) { + // Ignore + } + } + } } + diff --git a/python/src/com/jetbrains/python/console/PydevConsoleRunner.java b/python/src/com/jetbrains/python/console/PydevConsoleRunner.java index 0e2e3cd79297..96fde13ede93 100644 --- a/python/src/com/jetbrains/python/console/PydevConsoleRunner.java +++ b/python/src/com/jetbrains/python/console/PydevConsoleRunner.java @@ -3,12 +3,14 @@ package com.jetbrains.python.console; import com.google.common.collect.ImmutableMap; import com.intellij.execution.ExecutionException; import com.intellij.execution.ExecutionHelper; +import com.intellij.execution.Executor; import com.intellij.execution.console.LanguageConsoleImpl; import com.intellij.execution.console.LanguageConsoleViewImpl; import com.intellij.execution.process.CommandLineArgumentsProvider; import com.intellij.execution.process.ProcessOutputTypes; import com.intellij.execution.runners.AbstractConsoleRunnerWithHistory; import com.intellij.execution.runners.ConsoleExecuteActionHandler; +import com.intellij.execution.ui.RunContentDescriptor; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.project.Project; @@ -121,7 +123,7 @@ public class PydevConsoleRunner extends AbstractConsoleRunnerWithHistory { @Override protected PyConsoleProcessHandler createProcessHandler(final Process process, final String commandLine) { - myProcessHandler = new PyConsoleProcessHandler(process, getConsoleView().getConsole(), commandLine, + myProcessHandler = new PyConsoleProcessHandler(process, getConsoleView().getConsole(), myPydevConsoleCommunication, commandLine, CharsetToolkit.UTF8_CHARSET); return myProcessHandler; } @@ -185,6 +187,17 @@ public class PydevConsoleRunner extends AbstractConsoleRunnerWithHistory { @Override protected AnAction createStopAction() { final AnAction generalStopAction = super.createStopAction(); + return createConsoleStoppingAction(generalStopAction); + } + + @Override + protected AnAction createCloseAction(Executor defaultExecutor, RunContentDescriptor myDescriptor) { + final AnAction generalCloseAction = super.createCloseAction(defaultExecutor, myDescriptor); + return createConsoleStoppingAction(generalCloseAction); + } + + + private AnAction createConsoleStoppingAction(final AnAction generalStopAction) { final AnAction stopAction = new AnAction() { @Override public void update(AnActionEvent e) { diff --git a/python/src/com/jetbrains/python/inspections/PyCompatibilityInspection.java b/python/src/com/jetbrains/python/inspections/PyCompatibilityInspection.java index d5a4d89afdbc..ce0e5372b8f3 100644 --- a/python/src/com/jetbrains/python/inspections/PyCompatibilityInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyCompatibilityInspection.java @@ -29,13 +29,9 @@ public class PyCompatibilityInspection extends PyInspection { public String fromVersion = LanguageLevel.PYTHON24.toString(); public String toVersion = LanguageLevel.PYTHON27.toString(); - private List myVersionsToProcess; - public PyCompatibilityInspection () { super(); if (ApplicationManager.getApplication().isUnitTestMode()) toVersion = LanguageLevel.PYTHON31.toString(); - myVersionsToProcess = new ArrayList(); - updateVersionsToProcess(); } @Override @@ -43,8 +39,8 @@ public class PyCompatibilityInspection extends PyInspection { return false; } - private void updateVersionsToProcess() { - myVersionsToProcess.clear(); + private List updateVersionsToProcess() { + List result = new ArrayList(); boolean add = false; for (String version : UnsupportedFeaturesUtil.ALL_LANGUAGE_LEVELS) { @@ -52,12 +48,13 @@ public class PyCompatibilityInspection extends PyInspection { if (version.equals(fromVersion)) add = true; if (version.equals(toVersion)) { - myVersionsToProcess.add(level); + result.add(level); add = false; } if (add) - myVersionsToProcess.add(level); + result.add(level); } + return result; } @Nls @@ -102,8 +99,7 @@ public class PyCompatibilityInspection extends PyInspection { @NotNull @Override public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly) { - updateVersionsToProcess(); - return new Visitor(holder, myVersionsToProcess); + return new Visitor(holder, updateVersionsToProcess()); } private static class Visitor extends CompatibilityVisitor { diff --git a/python/src/com/jetbrains/python/sdk/PythonSdkUpdater.java b/python/src/com/jetbrains/python/sdk/PythonSdkUpdater.java index 1d40bf5a9a4b..6fe8fe7d6e1c 100644 --- a/python/src/com/jetbrains/python/sdk/PythonSdkUpdater.java +++ b/python/src/com/jetbrains/python/sdk/PythonSdkUpdater.java @@ -27,7 +27,7 @@ import java.util.List; public class PythonSdkUpdater implements ProjectComponent { private static final Logger LOG = Logger.getInstance("#com.jetbrains.python.sdk.PythonSdkUpdater"); - public static int SKELETONS_VERSION = 16; + public static int SKELETONS_VERSION = 17; public PythonSdkUpdater(final Project project, StartupManager startupManager) { if (ApplicationManager.getApplication().isUnitTestMode()) {