diff --git a/python/helpers/pydev/pydevd.py b/python/helpers/pydev/pydevd.py index 6ab83b956790..d0919c18d9b6 100644 --- a/python/helpers/pydev/pydevd.py +++ b/python/helpers/pydev/pydevd.py @@ -1,6 +1,5 @@ #IMPORTANT: pydevd_constants must be the 1st thing defined because it'll keep a reference to the original sys._getframe from __future__ import nested_scopes # Jython 2.1 support -from pydevd_constants import * # @UnusedWildImport import pydev_monkey_qt from pydevd_utils import save_main_module @@ -28,8 +27,7 @@ from pydevd_comm import CMD_CHANGE_VARIABLE, \ CMD_STEP_INTO, \ CMD_STEP_OVER, \ CMD_STEP_RETURN, \ - CMD_THREAD_CREATE, \ - CMD_THREAD_KILL, \ + CMD_THREAD_KILL, \ CMD_THREAD_RUN, \ CMD_THREAD_SUSPEND, \ CMD_RUN_TO_LINE, \ @@ -52,8 +50,7 @@ from pydevd_comm import CMD_CHANGE_VARIABLE, \ InternalTerminateThread, \ InternalRunThread, \ InternalStepThread, \ - NetCommand, \ - NetCommandFactory, \ + NetCommandFactory, \ PyDBDaemonThread, \ _queue, \ ReaderThread, \ @@ -65,8 +62,7 @@ from pydevd_comm import CMD_CHANGE_VARIABLE, \ StartServer, \ InternalSetNextStatementThread, \ ReloadCodeCommand, \ - ID_TO_MEANING,\ - CMD_SET_PY_EXCEPTION, \ + CMD_SET_PY_EXCEPTION, \ CMD_IGNORE_THROWN_EXCEPTION_AT,\ InternalGetBreakpointException, \ InternalSendCurrExceptionTrace,\ @@ -382,16 +378,16 @@ class PyDB: def haveAliveThreads(self): for t in threadingEnumerate(): - if isinstance(t, PyDBDaemonThread): - pydev_log.error_once( - 'Error in debugger: Found PyDBDaemonThread through threading.enumerate().\n') - if getattr(t, 'is_pydev_daemon_thread', False): #Important: Jython 2.5rc4 has a bug where a thread created with thread.start_new_thread won't be #set as a daemon thread, so, we also have to check for the 'is_pydev_daemon_thread' flag. #See: https://github.com/fabioz/PyDev.Debugger/issues/11 continue - + + if isinstance(t, PyDBDaemonThread): + pydev_log.error_once( + 'Error in debugger: Found PyDBDaemonThread not marked with is_pydev_daemon_thread=True.\n') + if isThreadAlive(t) and not t.isDaemon(): return True @@ -495,7 +491,7 @@ class PyDB: _DebugConsoleHelper._return_control_osc = not _DebugConsoleHelper._return_control_osc return _DebugConsoleHelper._return_control_osc - from pydev_ipython.inputhook import get_inputhook, set_return_control_callback + from pydev_ipython.inputhook import set_return_control_callback set_return_control_callback(return_control) from pydev_import_hook import import_hook_manager diff --git a/python/helpers/pydev/pydevd_comm.py b/python/helpers/pydev/pydevd_comm.py index bf8e2db148df..b9db00e9fced 100644 --- a/python/helpers/pydev/pydevd_comm.py +++ b/python/helpers/pydev/pydevd_comm.py @@ -57,7 +57,6 @@ each command has a format: * JAVA - remote debugger, the java end * PYDB - pydevd, the python end ''' -import sys from pydevd_constants import * #@UnusedWildImport from _pydev_imps import _pydev_time as time, _pydev_thread @@ -245,6 +244,8 @@ def SetGlobalDebugger(dbg): # PyDBDaemonThread #======================================================================================================================= class PyDBDaemonThread(threading.Thread): + created_pydb_daemon_threads = {} + def __init__(self): threading.Thread.__init__(self) self.setDaemon(True) @@ -253,13 +254,22 @@ class PyDBDaemonThread(threading.Thread): self.is_pydev_daemon_thread = True def run(self): - if sys.platform.startswith("java"): - import org.python.core as PyCore #@UnresolvedImport - ss = PyCore.PySystemState() - # Note: Py.setSystemState() affects only the current thread. - PyCore.Py.setSystemState(ss) + created_pydb_daemon = self.created_pydb_daemon_threads + created_pydb_daemon[self] = 1 + try: + try: + if IS_JYTHON: + import org.python.core as PyCore #@UnresolvedImport + ss = PyCore.PySystemState() + # Note: Py.setSystemState() affects only the current thread. + PyCore.Py.setSystemState(ss) - self.OnRun() + self.OnRun() + except: + if sys is not None and traceback is not None: + traceback.print_exc() + finally: + del created_pydb_daemon[self] def OnRun(self): raise NotImplementedError('Should be reimplemented by: %s' % self.__class__) @@ -270,7 +280,18 @@ class PyDBDaemonThread(threading.Thread): def stopTrace(self): if self.dontTraceMe: - pydevd_tracing.SetTrace(None) # no debugging on this thread + + disable_tracing = True + + if pydevd_vm_type.GetVmType() == pydevd_vm_type.PydevdVmType.JYTHON and sys.hexversion <= 0x020201f0: + # don't run untraced threads if we're in jython 2.2.1 or lower + # jython bug: if we start a thread and another thread changes the tracing facility + # it affects other threads (it's not set only for the thread but globally) + # Bug: http://sourceforge.net/tracker/index.php?func=detail&aid=1870039&group_id=12867&atid=112867 + disable_tracing = False + + if disable_tracing: + pydevd_tracing.SetTrace(None) # no debugging on this thread #=======================================================================================================================