From 7379199fbf657cb8ce4dde54c7fa43cac15cee52 Mon Sep 17 00:00:00 2001 From: Dmitry Trofimov Date: Mon, 13 Dec 2010 23:30:31 +0300 Subject: [PATCH 1/4] change connecting state in variables view (PY-2449) --- python/helpers/pydev/pydevd.py | 24 ++++++++++++++----- python/helpers/pydev/pydevd_comm.py | 4 ++-- .../python/debugger/pydev/RemoteDebugger.java | 2 ++ .../python/debugger/PyDebugProcess.java | 13 ++++++++++ 4 files changed, 35 insertions(+), 8 deletions(-) diff --git a/python/helpers/pydev/pydevd.py b/python/helpers/pydev/pydevd.py index e388560713bf..9c92a8795268 100644 --- a/python/helpers/pydev/pydevd.py +++ b/python/helpers/pydev/pydevd.py @@ -204,7 +204,6 @@ class PyDB: def FinishDebuggingSession(self): self._finishDebuggingSession = True - def acquire(self): if PyDBUseLocks: self.lock.acquire() @@ -279,6 +278,16 @@ class PyDB: queue = self.getInternalQueue(thread_id) queue.put(int_cmd) + def checkOutputRedirect(self): + global bufferStdOutToServer + global bufferStdErrToServer + + if bufferStdOutToServer: + self.checkOutput(sys.stdoutBuf, 1) #@UndefinedVariable + + if bufferStdErrToServer: + self.checkOutput(sys.stderrBuf, 2) #@UndefinedVariable + def checkOutput(self, out, outCtx): '''Checks the output to see if we have to send some buffered output to the debug server @@ -288,6 +297,7 @@ class PyDB: try: v = out.getvalue() + if v: self.cmdFactory.makeIoMessage(v, outCtx, self) except: @@ -300,11 +310,8 @@ class PyDB: self.acquire() try: - if bufferStdOutToServer: - self.checkOutput(sys.stdoutBuf, 1) #@UndefinedVariable - - if bufferStdErrToServer: - self.checkOutput(sys.stderrBuf, 2) #@UndefinedVariable + + self.checkOutputRedirect() currThreadId = GetThreadId(threadingCurrentThread()) threads = threadingEnumerate() @@ -1000,6 +1007,9 @@ def SetTraceForParents(frame, dispatch_func): frame = frame.f_back del frame +def exit_hook(): + GetGlobalDebugger().checkOutputRedirect() + def settrace(host='localhost', stdoutToServer=False, stderrToServer=False, port=5678, suspend=True, trace_only_current_thread=True): '''Sets the tracing function with the pydev debug function and initializes needed facilities. @@ -1075,6 +1085,8 @@ def settrace(host='localhost', stdoutToServer=False, stderrToServer=False, port= thread.start_new = pydev_start_new_thread except: pass + + #sys.exitfunc = exit_hook PyDBCommandThread(debugger).start() diff --git a/python/helpers/pydev/pydevd_comm.py b/python/helpers/pydev/pydevd_comm.py index e6868cfd485b..9386760872e8 100644 --- a/python/helpers/pydev/pydevd_comm.py +++ b/python/helpers/pydev/pydevd_comm.py @@ -211,6 +211,7 @@ class PyDBDaemonThread(threading.Thread): def doKill(self): #that was not working very well because jython gave some socket errors self.killReceived = True + #======================================================================================================================= # ReaderThread @@ -232,8 +233,7 @@ class ReaderThread(PyDBDaemonThread): except: #just ignore that pass - - + def OnRun(self): pydevd_tracing.SetTrace(None) # no debugging on this thread buffer = "" diff --git a/python/pydevSrc/com/jetbrains/python/debugger/pydev/RemoteDebugger.java b/python/pydevSrc/com/jetbrains/python/debugger/pydev/RemoteDebugger.java index 4c56c16617a9..df0049616dbd 100644 --- a/python/pydevSrc/com/jetbrains/python/debugger/pydev/RemoteDebugger.java +++ b/python/pydevSrc/com/jetbrains/python/debugger/pydev/RemoteDebugger.java @@ -43,6 +43,7 @@ public class RemoteDebugger { private final Map myResponseQueue = new HashMap(); private final TempVarsHolder myTempVars = new TempVarsHolder(); + private final List myCloseListeners = Lists.newArrayList(); public RemoteDebugger(final IPyDebugProcess debugProcess, final ServerSocket serverSocket, final int timeout) { @@ -59,6 +60,7 @@ public class RemoteDebugger { return myConnected; } + public void waitForConnect() throws Exception { try { //noinspection SocketOpenedButNotSafelyClosed diff --git a/python/src/com/jetbrains/python/debugger/PyDebugProcess.java b/python/src/com/jetbrains/python/debugger/PyDebugProcess.java index 5decd4a2e7c0..ea24433cb15c 100644 --- a/python/src/com/jetbrains/python/debugger/PyDebugProcess.java +++ b/python/src/com/jetbrains/python/debugger/PyDebugProcess.java @@ -16,6 +16,7 @@ import com.intellij.openapi.ui.Messages; import com.intellij.openapi.util.Key; import com.intellij.xdebugger.XDebugProcess; import com.intellij.xdebugger.XDebugSession; +import com.intellij.xdebugger.XDebuggerBundle; import com.intellij.xdebugger.XSourcePosition; import com.intellij.xdebugger.breakpoints.XBreakpoint; import com.intellij.xdebugger.breakpoints.XBreakpointHandler; @@ -425,4 +426,16 @@ public class PyDebugProcess extends XDebugProcess implements IPyDebugProcess, Pr public PyStackFrame createStackFrame(PyStackFrameInfo frameInfo) { return new PyStackFrame(this, frameInfo); } + + @Override + public String getCurrentStateMessage() { + if (getSession().isStopped()) { + return XDebuggerBundle.message("debugger.state.message.disconnected"); + } else + if (myDebugger.isConnected()) { + return XDebuggerBundle.message("debugger.state.message.connected"); + } else { + return "Waiting for connection..."; + } + } } From c0c2377c6b366760907a5d59f8d4624e33a2f644 Mon Sep 17 00:00:00 2001 From: Dmitry Trofimov Date: Mon, 13 Dec 2010 23:39:34 +0300 Subject: [PATCH 2/4] added checks to catch PY-2305 next time --- python/helpers/pydev/pydevd_comm.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/python/helpers/pydev/pydevd_comm.py b/python/helpers/pydev/pydevd_comm.py index 9386760872e8..f610025f0ed4 100644 --- a/python/helpers/pydev/pydevd_comm.py +++ b/python/helpers/pydev/pydevd_comm.py @@ -259,7 +259,13 @@ class ReaderThread(PyDBDaemonThread): command, buffer = buffer.split('\n', 1) PydevdLog(1, "received command ", command) args = command.split('\t', 2) - GlobalDebuggerHolder.globalDbg.processNetCommand(int(args[0]), int(args[1]), args[2]) + try: + GlobalDebuggerHolder.globalDbg.processNetCommand(int(args[0]), int(args[1]), args[2]) + except: + traceback.print_exc() + sys.stderr.write("Can't process net command %" % command) + sys.stderr.flush() + except: traceback.print_exc() GlobalDebuggerHolder.globalDbg.FinishDebuggingSession() From 52ca7fbc661450b0774bf123acf5ce7dc48a8908 Mon Sep 17 00:00:00 2001 From: Dmitry Trofimov Date: Tue, 14 Dec 2010 18:01:29 +0300 Subject: [PATCH 3/4] fixed error on breakpoints update (PY-2473) --- python/helpers/pydev/pydevd.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/python/helpers/pydev/pydevd.py b/python/helpers/pydev/pydevd.py index 9c92a8795268..9fbb2bc40522 100644 --- a/python/helpers/pydev/pydevd.py +++ b/python/helpers/pydev/pydevd.py @@ -637,8 +637,11 @@ class PyDB: exception = text exc_type = get_class(exception) if exc_type is not None: - exception_set.remove(exc_type) - always_exception_set.remove(exc_type) + try: + exception_set.remove(exc_type) + always_exception_set.remove(exc_type) + except: + pass update_exception_hook() elif cmd_id == CMD_LOAD_SOURCE: From ddadcf031db904582826032042540b0278d49118 Mon Sep 17 00:00:00 2001 From: Dmitry Trofimov Date: Tue, 14 Dec 2010 21:52:11 +0300 Subject: [PATCH 4/4] fixed remote debug run configuration ui (PY-2474) --- .../src/com/jetbrains/python/PyBundle.properties | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/python/src/com/jetbrains/python/PyBundle.properties b/python/src/com/jetbrains/python/PyBundle.properties index d9e0084e93dd..1a3a5fda3e60 100644 --- a/python/src/com/jetbrains/python/PyBundle.properties +++ b/python/src/com/jetbrains/python/PyBundle.properties @@ -518,15 +518,18 @@ run.configuration.remote.debug.name=Python Remote Debug run.configuration.type.description=Starts server for remote debug remote.debug.info=Info -remote.debug.server.hint=Run this remote debug configuration to start debug server. -remote.debug.server.hint2=Add pycharm-debug.egg from PyCharm distribution to python path of your script. -remote.debug.server.hint3=Use the following command in your script to connect to debug server: +remote.debug.server.hint=Launch this debug configuration to start the debug server. +remote.debug.server.hint1.5=Update your script: +remote.debug.server.hint2=1. Add pycharm-debug.egg from the PyCharm installation to the Python path. +remote.debug.server.hint2.5=2. Add the following import statement: +remote.debug.server.hint3=3. Add the following command to connect to the debug server: remote.debug.settings=Settings remote.debug.remote.host=Remote host remote.debug.port=Port -remote.debug.remote.root.folder=Remote root folder -remote.debug.local.root.folder=Local root folder +remote.debug.use.path.mapping=Use path mapping +remote.debug.remote.root.folder=Remote paths prefix +remote.debug.local.root.folder=Local paths prefix remote.debug.server.hint4=If you want to enable stdout and stderr redirection to PyCharm console, use following command in your script: remote.debug.local.host=Local host name: remote.debug.redirect.output=Redirect output to console -remote.debug.suspend.on.conect=Suspend after connect +remote.debug.suspend.on.connect=Suspend after connect