From aadc4211bff7034070b05ba30164b4268dd6d521 Mon Sep 17 00:00:00 2001 From: Dmitry Trofimov Date: Sun, 6 Oct 2013 23:00:02 +0200 Subject: [PATCH 1/5] Cleanup. --- .../console/pydev/PydevXmlRpcClient.java | 21 +------------------ 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/python/pydevSrc/com/jetbrains/python/console/pydev/PydevXmlRpcClient.java b/python/pydevSrc/com/jetbrains/python/console/pydev/PydevXmlRpcClient.java index 82f2e278d7fa..695704fa7874 100644 --- a/python/pydevSrc/com/jetbrains/python/console/pydev/PydevXmlRpcClient.java +++ b/python/pydevSrc/com/jetbrains/python/console/pydev/PydevXmlRpcClient.java @@ -1,6 +1,7 @@ package com.jetbrains.python.console.pydev; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.util.SystemInfo; import com.intellij.util.net.NetUtils; import org.apache.xmlrpc.*; @@ -47,26 +48,6 @@ public class PydevXmlRpcClient implements IPydevXmlRpcClient { String hostname = NetUtils.getLocalHostString(); - //try { - // Socket s = new Socket(hostname, port); - // PrintWriter p = new PrintWriter(s.getOutputStream()); - // p.println("Hi there"); - // p.flush(); - // Scanner sc = new Scanner(s.getInputStream()); - // try { - // Thread.sleep(1000); - // String line = sc.nextLine(); - // System.out.println(line); - // } - // catch (Exception e) { - // } - // s.close(); - //} - //catch (IOException e) { - // - //} - - URL url = new URL("http://" + hostname + ':' + port + "/RPC2"); XmlRpc.setDefaultInputEncoding("UTF8"); //eventhough it uses UTF anyway From ba9cab5b6da60ac3a3892d354308e9c1a2ebcaee Mon Sep 17 00:00:00 2001 From: Dmitry Trofimov Date: Mon, 7 Oct 2013 00:01:17 +0200 Subject: [PATCH 2/5] Ports of remote console should be obtained regardless of other output generated by the process (PY-11028). --- .../python/console/PydevConsoleRunner.java | 54 ++++++++++--------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/python/src/com/jetbrains/python/console/PydevConsoleRunner.java b/python/src/com/jetbrains/python/console/PydevConsoleRunner.java index 7798fcef809d..1c50c67b4768 100644 --- a/python/src/com/jetbrains/python/console/PydevConsoleRunner.java +++ b/python/src/com/jetbrains/python/console/PydevConsoleRunner.java @@ -316,44 +316,46 @@ public class PydevConsoleRunner extends AbstractConsoleRunnerWithHistory getRemotePortsFromProcess(RemoteSshProcess process) throws ExecutionException { Scanner s = new Scanner(process.getInputStream()); + return Pair.create(readInt(s, process), readInt(s, process)); + } + private static int readInt(Scanner s, Process process) throws ExecutionException { long started = System.currentTimeMillis(); while (System.currentTimeMillis() - started < PORTS_WAITING_TIMEOUT) { - try { - int port = s.nextInt(); - int port2 = s.nextInt(); - - return Pair.create(port, port2); - } - catch (Exception e) { + if (s.hasNextLine()) { + String line = s.nextLine(); try { - Thread.sleep(200); + return Integer.parseInt(line); } - catch (InterruptedException e1) { + catch (NumberFormatException e) { + continue; } } + try { - if (process.exitValue() != 0) { - String error; - try { - error = "Console process terminated with error:\n" + StreamUtil.readText(process.getErrorStream()); - } - catch (Exception e) { - error = "Console process terminated with exit code " + process.exitValue(); - } - throw new ExecutionException(error); - } - else { - break; - } + + Thread.sleep(200); } - catch (IllegalThreadStateException e) { - //continue + catch (InterruptedException e1) { + } + + if (process.exitValue() != 0) { + String error; + try { + error = "Console process terminated with error:\n" + StreamUtil.readText(process.getErrorStream()); + } + catch (Exception e) { + error = "Console process terminated with exit code " + process.exitValue(); + } + throw new ExecutionException(error); + } + else { + break; } } - throw new ExecutionException("Couldn't get remote ports for console connection."); + throw new ExecutionException("Couldn't read integer value from stream"); } @Override @@ -682,7 +684,7 @@ public class PydevConsoleRunner extends AbstractConsoleRunnerWithHistory Date: Mon, 7 Oct 2013 00:24:08 +0200 Subject: [PATCH 3/5] Don't show deprecation warning for IPython 1.1.0 (PY-10800). --- python/helpers/pydev/pydev_ipython_console.py | 4 ++-- python/helpers/pydev/pydev_ipython_console_011.py | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/python/helpers/pydev/pydev_ipython_console.py b/python/helpers/pydev/pydev_ipython_console.py index dca3b4dc53ee..d3d4ae8492a3 100644 --- a/python/helpers/pydev/pydev_ipython_console.py +++ b/python/helpers/pydev/pydev_ipython_console.py @@ -11,10 +11,10 @@ os.environ['TERM'] = 'emacs' #to use proper page_more() for paging #raise ImportError() try: - from pydev_ipython_console_010 import PyDevFrontEnd -except: #IPython 0.11 broke compatibility... from pydev_ipython_console_011 import PyDevFrontEnd +except: + from pydev_ipython_console_010 import PyDevFrontEnd #======================================================================================================================= # InterpreterInterface diff --git a/python/helpers/pydev/pydev_ipython_console_011.py b/python/helpers/pydev/pydev_ipython_console_011.py index da08bd136ab5..a6c0d8207a04 100644 --- a/python/helpers/pydev/pydev_ipython_console_011.py +++ b/python/helpers/pydev/pydev_ipython_console_011.py @@ -1,4 +1,7 @@ -from IPython.frontend.terminal.interactiveshell import TerminalInteractiveShell +try: + from IPython.terminal.interactiveshell import TerminalInteractiveShell +except ImportError: + from IPython.frontend.terminal.interactiveshell import TerminalInteractiveShell from IPython.utils import io import sys import codeop, re From ab671c0b7d1cf95ee7c245e3b6bc7594fdb03568 Mon Sep 17 00:00:00 2001 From: Dmitry Trofimov Date: Mon, 7 Oct 2013 01:35:15 +0200 Subject: [PATCH 4/5] quote function cat raise an error (PY-3265). --- python/helpers/pydev/pydevd_xml.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/python/helpers/pydev/pydevd_xml.py b/python/helpers/pydev/pydevd_xml.py index 9347472157c5..73258e6fcc65 100644 --- a/python/helpers/pydev/pydevd_xml.py +++ b/python/helpers/pydev/pydevd_xml.py @@ -171,7 +171,11 @@ def varToXML(val, name, doTrim=True): except: value = 'Unable to get repr for %s' % v.__class__ - xml = '_= ')), makeValidXmlValue(typeName)) + try: + name = quote(name, '/>_= ') #TODO: Fix PY-5834 without using quote + except: + pass + xml = ' Date: Mon, 7 Oct 2013 02:57:22 +0200 Subject: [PATCH 5/5] stoptrace method added (PY-4711, PY-4714). --- python/helpers/pydev/pydevd.py | 42 ++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/python/helpers/pydev/pydevd.py b/python/helpers/pydev/pydevd.py index b75d388bc80b..031d6a15b662 100644 --- a/python/helpers/pydev/pydevd.py +++ b/python/helpers/pydev/pydevd.py @@ -155,6 +155,13 @@ class PyDBCommandThread(PyDBDaemonThread): #PydevdLog(0, 'Finishing debug communication...(3)') +def killAllPydevThreads(): + threads = threadingEnumerate() + for t in threads: + if hasattr(t, 'doKillPydevThread'): + t.doKillPydevThread() + + #======================================================================================================================= # PyDBCheckAliveThread #======================================================================================================================= @@ -174,10 +181,7 @@ class PyDBCheckAliveThread(PyDBDaemonThread): try: pydev_log.debug("No alive threads, finishing debug session") self.pyDb.FinishDebuggingSession() - threads = threadingEnumerate() - for t in threads: - if hasattr(t, 'doKillPydevThread'): - t.doKillPydevThread() + killAllPydevThreads() except: traceback.print_exc() @@ -1351,6 +1355,36 @@ def _locked_settrace(host, stdoutToServer, stderrToServer, port, suspend, trace_ if suspend: debugger.setSuspend(t, CMD_SET_BREAK) +def stoptrace(): + global connected + if connected: + pydevd_tracing.RestoreSysSetTraceFunc() + sys.settrace(None) + try: + #not available in jython! + threading.settrace(None) # for all future threads + except: + pass + + try: + thread.start_new_thread = _original_start_new_thread + thread.start_new = _original_start_new_thread + except: + pass + + debugger = GetGlobalDebugger() + + if debugger: + debugger.trace_dispatch = None + + debugger.SetTraceForFrameAndParents(GetFrame(), False) + + debugger.exiting() + + killAllPydevThreads() + + connected = False + class Dispatcher(object): def __init__(self): self.port = None