From 56afc0cb660ef6a03fb2a2994639355f113ac3db Mon Sep 17 00:00:00 2001 From: Dmitry Trofimov Date: Mon, 5 Dec 2011 12:44:02 +0100 Subject: [PATCH 1/4] Python: don't kill softly in suspend debug mode (PY-5185). --- python/helpers/pydev/pydevconsole.py | 9 +++++---- .../com/jetbrains/python/debugger/PyDebugProcess.java | 11 +++++++++-- .../com/jetbrains/python/debugger/PyDebugRunner.java | 5 +---- .../jetbrains/python/run/PythonProcessHandler.java | 11 +++++++++++ .../com/jetbrains/python/run/PythonProcessRunner.java | 4 ++-- 5 files changed, 28 insertions(+), 12 deletions(-) diff --git a/python/helpers/pydev/pydevconsole.py b/python/helpers/pydev/pydevconsole.py index 69c03cd25fb6..1aad93b008ee 100644 --- a/python/helpers/pydev/pydevconsole.py +++ b/python/helpers/pydev/pydevconsole.py @@ -183,9 +183,6 @@ def process_exec_queue(interpreter): continue -def ExitPass(): - pass - try: try: exitfunc = sys.exitfunc @@ -195,8 +192,12 @@ try: IPYTHON = True if exitfunc is not None: sys.exitfunc = exitfunc + else: - sys.exitfunc = ExitPass + try: + delattr(sys, 'exitfunc') + except : + pass except: IPYTHON = False #sys.stderr.write('PyDev console: started.\n') diff --git a/python/src/com/jetbrains/python/debugger/PyDebugProcess.java b/python/src/com/jetbrains/python/debugger/PyDebugProcess.java index 1a7ac4d2be55..b09cdcf8d802 100644 --- a/python/src/com/jetbrains/python/debugger/PyDebugProcess.java +++ b/python/src/com/jetbrains/python/debugger/PyDebugProcess.java @@ -31,6 +31,7 @@ import com.jetbrains.django.util.DjangoUtil; import com.jetbrains.python.console.pydev.PydevCompletionVariant; import com.jetbrains.python.debugger.django.DjangoExceptionBreakpointHandler; import com.jetbrains.python.debugger.pydev.*; +import com.jetbrains.python.run.PythonProcessHandler; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -288,7 +289,7 @@ public class PyDebugProcess extends XDebugProcess implements IPyDebugProcess, Pr @Override public void stop() { - myDebugger.disconnect(); + //myDebugger.disconnect(); } @Override @@ -532,7 +533,13 @@ public class PyDebugProcess extends XDebugProcess implements IPyDebugProcess, Pr @Override public void processWillTerminate(ProcessEvent event, boolean willBeDestroyed) { myClosing = true; - myDebugger.close(); + setKillingStrategy(); + } + + private void setKillingStrategy() { + if (getSession().isSuspended() && myProcessHandler instanceof PythonProcessHandler) { + ((PythonProcessHandler)myProcessHandler).setShouldTryToKillSoftly(false); //while process is suspended it can't terminate softly, so its better to kill all the tree hard + } } @Override diff --git a/python/src/com/jetbrains/python/debugger/PyDebugRunner.java b/python/src/com/jetbrains/python/debugger/PyDebugRunner.java index 816e71120b66..b89f7cae2f7a 100644 --- a/python/src/com/jetbrains/python/debugger/PyDebugRunner.java +++ b/python/src/com/jetbrains/python/debugger/PyDebugRunner.java @@ -25,10 +25,7 @@ import com.jetbrains.python.console.PythonConsoleView; import com.jetbrains.python.console.PythonDebugConsoleCommunication; import com.jetbrains.python.console.PythonDebugLanguageConsoleView; import com.jetbrains.python.console.pydev.ConsoleCommunication; -import com.jetbrains.python.run.AbstractPythonRunConfiguration; -import com.jetbrains.python.run.CommandLinePatcher; -import com.jetbrains.python.run.PythonCommandLineState; -import com.jetbrains.python.run.PythonRunConfiguration; +import com.jetbrains.python.run.*; import com.jetbrains.python.sdk.PythonSdkFlavor; import com.jetbrains.rest.run.RestRunConfiguration; import org.jetbrains.annotations.NotNull; diff --git a/python/src/com/jetbrains/python/run/PythonProcessHandler.java b/python/src/com/jetbrains/python/run/PythonProcessHandler.java index 436051648eb4..8db1b81955fe 100644 --- a/python/src/com/jetbrains/python/run/PythonProcessHandler.java +++ b/python/src/com/jetbrains/python/run/PythonProcessHandler.java @@ -12,6 +12,8 @@ import java.nio.charset.Charset; * @author traff */ public class PythonProcessHandler extends KillableColoredProcessHandler { + private boolean myShouldTryToKillSoftly = true; + protected PythonProcessHandler(@NotNull Process process, @NotNull GeneralCommandLine commandLine) { super(process, commandLine.getCommandLineString()); } @@ -20,6 +22,15 @@ public class PythonProcessHandler extends KillableColoredProcessHandler { super(process, commandLine, charset); } + public void setShouldTryToKillSoftly(boolean shouldTryToKillSoftly) { + myShouldTryToKillSoftly = shouldTryToKillSoftly; + } + + @Override + public boolean canKillSoftly() { + return super.canKillSoftly() && myShouldTryToKillSoftly; + } + @Override protected boolean shouldDestroyProcessRecursively() { return true; diff --git a/python/src/com/jetbrains/python/run/PythonProcessRunner.java b/python/src/com/jetbrains/python/run/PythonProcessRunner.java index b19b3d6dc714..7c02ec342e4b 100644 --- a/python/src/com/jetbrains/python/run/PythonProcessRunner.java +++ b/python/src/com/jetbrains/python/run/PythonProcessRunner.java @@ -4,6 +4,7 @@ import com.intellij.execution.ExecutionException; import com.intellij.execution.configurations.GeneralCommandLine; import com.intellij.execution.process.ProcessHandler; import com.intellij.execution.process.RunnerMediator; +import com.intellij.openapi.util.SystemInfo; import com.jetbrains.python.sdk.JythonSdkFlavor; import com.jetbrains.python.sdk.PythonSdkFlavor; @@ -19,7 +20,7 @@ public class PythonProcessRunner { return JythonProcessHandler.createProcessHandler(commandLine); } else { - if (withMediator) { + if (withMediator && SystemInfo.isWindows) { return RunnerMediator.getInstance().createProcess(commandLine); } else { @@ -35,5 +36,4 @@ public class PythonProcessRunner { public static ProcessHandler createProcessHandlingCtrlC(GeneralCommandLine commandLine) throws ExecutionException { return createProcess(commandLine, true); } - } From ccd38d96648879a565bbe434f399d440c0c8659f Mon Sep 17 00:00:00 2001 From: Dmitry Trofimov Date: Mon, 5 Dec 2011 14:12:59 +0100 Subject: [PATCH 2/4] Fixed debugger disconnection. --- python/src/com/jetbrains/python/debugger/PyDebugProcess.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/python/src/com/jetbrains/python/debugger/PyDebugProcess.java b/python/src/com/jetbrains/python/debugger/PyDebugProcess.java index b09cdcf8d802..c9a6e43a03d1 100644 --- a/python/src/com/jetbrains/python/debugger/PyDebugProcess.java +++ b/python/src/com/jetbrains/python/debugger/PyDebugProcess.java @@ -289,7 +289,7 @@ public class PyDebugProcess extends XDebugProcess implements IPyDebugProcess, Pr @Override public void stop() { - //myDebugger.disconnect(); + myDebugger.disconnect(); } @Override @@ -528,6 +528,7 @@ public class PyDebugProcess extends XDebugProcess implements IPyDebugProcess, Pr @Override public void processTerminated(ProcessEvent event) { + myDebugger.close(); } @Override From 7b901b502c222394e1571e6e538dc0fd5c2f7607 Mon Sep 17 00:00:00 2001 From: Dmitry Trofimov Date: Mon, 5 Dec 2011 17:55:57 +0100 Subject: [PATCH 3/4] Fixed run to cursor temp breakpoint removal (PY-4465). --- python/helpers/pydev/pydevd.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/python/helpers/pydev/pydevd.py b/python/helpers/pydev/pydevd.py index 2d5fe30fe309..d22a0a2c23af 100644 --- a/python/helpers/pydev/pydevd.py +++ b/python/helpers/pydev/pydevd.py @@ -612,6 +612,7 @@ class PyDB: pass else: + found = False try: if type == 'django-line': del self.django_breakpoints[file][line] @@ -620,14 +621,22 @@ class PyDB: else: try: del self.django_breakpoints[file][line] + found = True + except: + pass + try: del self.breakpoints[file][line] #remove the breakpoint in that line + found = True except: pass if DebugInfoHolder.DEBUG_TRACE_BREAKPOINTS > 0: - sys.stderr.write('Removed breakpoint:%s\n' % (file,)) + sys.stderr.write('Removed breakpoint:%s - %s\n' % (file, line)) sys.stderr.flush() except KeyError: + found = False + + if not found: #ok, it's not there... if DebugInfoHolder.DEBUG_TRACE_BREAKPOINTS > 0: #Sometimes, when adding a breakpoint, it adds a remove command before (don't really know why) @@ -1279,7 +1288,7 @@ if __name__ == '__main__': pydevd_vm_type.SetupType(setup.get('vm_type', None)) DebugInfoHolder.DEBUG_RECORD_SOCKET_READS = setup.get('DEBUG_RECORD_SOCKET_READS', False) - DebugInfoHolder.DEBUG_TRACE_BREAKPOINTS = setup.get('', -1) + DebugInfoHolder.DEBUG_TRACE_BREAKPOINTS = setup.get('DEBUG_TRACE_BREAKPOINTS', -1) DebugInfoHolder.DEBUG_TRACE_LEVEL = setup.get('DEBUG_TRACE_LEVEL', -1) port = setup['port'] From ac3e2ea0c79bc8132f05f98c7f7ed8e6bc33fada Mon Sep 17 00:00:00 2001 From: Dmitry Trofimov Date: Mon, 5 Dec 2011 18:09:00 +0100 Subject: [PATCH 4/4] Fixed twice-monkey-patch (PY-5223). --- python/helpers/pydev/pydev_monkey.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/python/helpers/pydev/pydev_monkey.py b/python/helpers/pydev/pydev_monkey.py index bd2f23f479b5..336b51ef90cb 100644 --- a/python/helpers/pydev/pydev_monkey.py +++ b/python/helpers/pydev/pydev_monkey.py @@ -48,8 +48,9 @@ def patch_args(args): def monkey_patch_os(funcname, create_func): if hasattr(os, funcname): original_name = 'original_' + funcname - setattr(os, original_name, getattr(os, funcname)) - setattr(os, funcname, create_func(original_name)) + if not hasattr(os, original_name): + setattr(os, original_name, getattr(os, funcname)) + setattr(os, funcname, create_func(original_name)) def create_execl(original_name): def new_execl(path, *args):