diff --git a/python/helpers/pydev/pydevconsole.py b/python/helpers/pydev/pydevconsole.py index e1c85c59778e..fd2086b08d88 100644 --- a/python/helpers/pydev/pydevconsole.py +++ b/python/helpers/pydev/pydevconsole.py @@ -156,7 +156,7 @@ class InterpreterInterface(BaseInterpreterInterface): completer = Completer(self.namespace, None) return completer.complete(act_tok) except: - import traceback; + import traceback traceback.print_exc() return [] @@ -183,15 +183,8 @@ def process_exec_queue(interpreter): raise except: type, value, tb = sys.exc_info() - try: - print_exception() - rpc.response_queue.put((seq, None)) - except: - # Link didn't work, print same exception to __stderr__ - traceback.print_exception(type, value, tb, file=sys.__stderr__) - exit() - else: - continue + traceback.print_exception(type, value, tb, file=sys.__stderr__) + exit() try: diff --git a/python/src/com/jetbrains/python/console/PydevConsoleCommunication.java b/python/src/com/jetbrains/python/console/PydevConsoleCommunication.java index a3cabfddb7d6..3b25dcf9ae12 100644 --- a/python/src/com/jetbrains/python/console/PydevConsoleCommunication.java +++ b/python/src/com/jetbrains/python/console/PydevConsoleCommunication.java @@ -37,12 +37,12 @@ public class PydevConsoleCommunication extends AbstractConsoleCommunication impl /** * XML-RPC client for sending messages to the server. */ - private IPydevXmlRpcClient client; + private IPydevXmlRpcClient myClient; /** * This is the server responsible for giving input to a raw_input() requested. */ - private WebServer webServer; + private WebServer myWebServer; private static final Logger LOG = Logger.getInstance(PydevConsoleCommunication.class.getName()); @@ -78,16 +78,16 @@ public class PydevConsoleCommunication extends AbstractConsoleCommunication impl super(project); //start the server that'll handle input requests - webServer = new IdeaAwareWebServer(clientPort, null, new IdeaAwareXmlRpcServer()); - webServer.addHandler("$default", this); - this.webServer.start(); + myWebServer = new IdeaAwareWebServer(clientPort, null, new IdeaAwareXmlRpcServer()); + myWebServer.addHandler("$default", this); + this.myWebServer.start(); - this.client = new PydevXmlRpcClient(process, port); + this.myClient = new PydevXmlRpcClient(process, port); } public boolean handshake() throws XmlRpcException { - if (client != null) { - Object ret = client.execute(HANDSHAKE, new Object[]{}); + if (myClient != null) { + Object ret = myClient.execute(HANDSHAKE, new Object[]{}); if (ret instanceof String) { String retVal = (String)ret; return "PyCharm".equals(retVal); @@ -99,25 +99,25 @@ public class PydevConsoleCommunication extends AbstractConsoleCommunication impl /** * Stops the communication with the client (passes message for it to quit). */ - public void close() { - if (this.client != null) { + public synchronized void close() { + if (this.myClient != null) { new Task.Backgroundable(myProject, "Close console communication", true) { @Override public void run(@NotNull ProgressIndicator indicator) { try { - PydevConsoleCommunication.this.client.execute(CLOSE, new Object[0]); + PydevConsoleCommunication.this.myClient.execute(CLOSE, new Object[0]); } catch (Exception e) { //Ok, we can ignore this one on close. } - PydevConsoleCommunication.this.client = null; + PydevConsoleCommunication.this.myClient = null; } }.queue(); } - if (this.webServer != null) { - this.webServer.shutdown(); - this.webServer = null; + if (myWebServer != null) { + myWebServer.shutdown(); + myWebServer = null; } } @@ -236,7 +236,7 @@ public class PydevConsoleCommunication extends AbstractConsoleCommunication impl */ protected Pair exec(final String command) throws XmlRpcException { setExecuting(true); - Object execute = client.execute(EXEC_LINE, new Object[]{command}); + Object execute = myClient.execute(EXEC_LINE, new Object[]{command}); Object object; if (execute instanceof Vector) { @@ -264,7 +264,7 @@ public class PydevConsoleCommunication extends AbstractConsoleCommunication impl if (waitingForInput) { return Collections.emptyList(); } - final Object fromServer = client.execute(GET_COMPLETIONS, new Object[]{text, actTok}); + final Object fromServer = myClient.execute(GET_COMPLETIONS, new Object[]{text, actTok}); return PydevXmlUtils.decodeCompletions(fromServer); } @@ -276,7 +276,7 @@ public class PydevConsoleCommunication extends AbstractConsoleCommunication impl if (waitingForInput) { return "Unable to get description: waiting for input."; } - return client.execute(GET_DESCRIPTION, new Object[]{text}).toString(); + return myClient.execute(GET_DESCRIPTION, new Object[]{text}).toString(); } /** @@ -395,7 +395,7 @@ public class PydevConsoleCommunication extends AbstractConsoleCommunication impl @Override public void interrupt() { try { - client.execute("interrupt", new Object[]{}); + myClient.execute("interrupt", new Object[]{}); } catch (XmlRpcException e) { LOG.error(e); diff --git a/python/src/com/jetbrains/python/console/PydevConsoleRunner.java b/python/src/com/jetbrains/python/console/PydevConsoleRunner.java index 82c68d8fbc7b..2cecb76e6fc5 100644 --- a/python/src/com/jetbrains/python/console/PydevConsoleRunner.java +++ b/python/src/com/jetbrains/python/console/PydevConsoleRunner.java @@ -29,7 +29,6 @@ import com.intellij.openapi.progress.Task; import com.intellij.openapi.project.DumbAwareAction; import com.intellij.openapi.project.Project; import com.intellij.openapi.projectRoots.Sdk; -import com.intellij.openapi.ui.Messages; import com.intellij.openapi.util.Key; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.CharsetToolkit; @@ -40,8 +39,8 @@ import com.intellij.psi.impl.source.tree.FileElement; import com.intellij.testFramework.LightVirtualFile; import com.intellij.util.ArrayUtil; import com.intellij.util.IJSwingUtilities; -import com.intellij.util.concurrency.Semaphore; import com.intellij.util.net.NetUtils; +import com.intellij.util.ui.UIUtil; import com.jetbrains.django.run.Runner; import com.jetbrains.plugins.remotesdk.RemoteInterpreterException; import com.jetbrains.plugins.remotesdk.RemoteSdkData; @@ -50,7 +49,6 @@ import com.jetbrains.python.PythonHelpersLocator; import com.jetbrains.python.console.completion.PydevConsoleElement; import com.jetbrains.python.console.parsing.PythonConsoleData; import com.jetbrains.python.console.pydev.ConsoleCommunication; -import com.jetbrains.python.console.pydev.ConsoleCommunicationListener; import com.jetbrains.python.debugger.PySourcePosition; import com.jetbrains.python.remote.PythonRemoteInterpreterManager; import com.jetbrains.python.run.PythonCommandLineState; @@ -485,21 +483,8 @@ public class PydevConsoleRunner extends AbstractConsoleRunnerWithHistory escaperFunction = StringUtil.escaper(false, "|>$\"'& "); - StringBuilder paramString = new StringBuilder(escaperFunction.fun(homePath) + " " +escaperFunction.fun(myRunnerScript)); + StringBuilder paramString = new StringBuilder(escaperFunction.fun(homePath) + " " + escaperFunction.fun(myRunnerScript)); for (String p : myParameters) { paramString.append(" ").append(p); @@ -152,8 +153,9 @@ public class PythonTask { protected List setupPythonPath(final boolean addProjectRoot) { final List pythonPath = Lists.newArrayList(PythonCommandLineState.getAddedPaths(mySdk)); - if (addProjectRoot) + if (addProjectRoot) { pythonPath.addAll(PythonCommandLineState.collectPythonPath(myModule)); + } return pythonPath; } @@ -174,6 +176,19 @@ public class PythonTask { } } }) + .withStop(new Runnable() { + @Override + public void run() { + process.destroyProcess(); + } + }, new Computable() { + + @Override + public Boolean compute() { + return !process.isProcessTerminated(); + } + } + ) .withAfterCompletion(myAfterCompletion) .withHelpId(myHelpId) .run(); diff --git a/python/src/com/jetbrains/python/validation/Pep8ExternalAnnotator.java b/python/src/com/jetbrains/python/validation/Pep8ExternalAnnotator.java index 86ec6ea131e1..4fed279eb99f 100644 --- a/python/src/com/jetbrains/python/validation/Pep8ExternalAnnotator.java +++ b/python/src/com/jetbrains/python/validation/Pep8ExternalAnnotator.java @@ -79,7 +79,11 @@ public class Pep8ExternalAnnotator extends ExternalAnnotator ignoredErrors = ((PyPep8Inspection) profileEntry.getTool()).ignoredErrors; + final List ignoredErrors = ((PyPep8Inspection)profileEntry.getTool()).ignoredErrors; final int margin = CodeStyleSettingsManager.getInstance(file.getProject()).getCurrentSettings().RIGHT_MARGIN; return new State(homePath, file.getText(), profile.getErrorLevel(key, file), ignoredErrors, margin); } @@ -127,8 +131,8 @@ public class Pep8ExternalAnnotator extends ExternalAnnotator