Debugger hangs on Jython with "Attach to subprocess" option enabled (PY-18742)
authorElizaveta Shashkova <Elizaveta.Shashkova@jetbrains.com>
Mon, 4 Apr 2016 17:26:51 +0000 (20:26 +0300)
committerElizaveta Shashkova <Elizaveta.Shashkova@jetbrains.com>
Mon, 4 Apr 2016 17:31:16 +0000 (20:31 +0300)
We shouldn't update sys.modules for the main thread, cause it leads to the second importing 'threading' module, and the new instance of main thread is created. In this case we lose thread id and thread additional info, so it totally breaks the debugger.

python/helpers/pydev/_pydevd_bundle/pydevd_comm.py

index d3c12f164dbb174e095de7686950e1accc4eb3fe..edebeb1f090549fd0de2fdb105f1d31041a6f75f 100644 (file)
@@ -265,7 +265,9 @@ class PyDBDaemonThread(threading.Thread):
         created_pydb_daemon[self] = 1
         try:
             try:
-                if IS_JYTHON:
+                if IS_JYTHON and not isinstance(threading.currentThread(), threading._MainThread):
+                    # we shouldn't update sys.modules for the main thread, cause it leads to the second importing 'threading'
+                    # module, and the new instance of main thread is created
                     import org.python.core as PyCore #@UnresolvedImport
                     ss = PyCore.PySystemState()
                     # Note: Py.setSystemState() affects only the current thread.