diff --git a/python/helpers/pydev/_pydev_bundle/pydev_monkey.py b/python/helpers/pydev/_pydev_bundle/pydev_monkey.py index 0532d36b843a..77ee6ff6890f 100644 --- a/python/helpers/pydev/_pydev_bundle/pydev_monkey.py +++ b/python/helpers/pydev/_pydev_bundle/pydev_monkey.py @@ -45,9 +45,7 @@ def _on_forked_process(): pydevd.threadingCurrentThread().__pydevd_main_thread = True pydevd.settrace_forked() -def _on_set_trace_for_new_thread(): - from _pydevd_bundle.pydevd_comm import get_global_debugger - global_debugger = get_global_debugger() +def _on_set_trace_for_new_thread(global_debugger): if global_debugger is not None: global_debugger.SetTrace(global_debugger.trace_dispatch) @@ -534,11 +532,15 @@ class _NewThreadStartupWithTrace: self.original_func = original_func self.args = args self.kwargs = kwargs + self.global_debugger = self.get_debugger() + + def get_debugger(self): + from _pydevd_bundle.pydevd_comm import get_global_debugger + return get_global_debugger() def __call__(self): - _on_set_trace_for_new_thread() - from _pydevd_bundle.pydevd_comm import get_global_debugger - global_debugger = get_global_debugger() + _on_set_trace_for_new_thread(self.global_debugger) + global_debugger = self.global_debugger if global_debugger is not None and global_debugger.thread_analyser is not None: # we can detect start_new_thread only here @@ -567,7 +569,10 @@ _UseNewThreadStartup = _NewThreadStartupWithTrace def _get_threading_modules_to_patch(): threading_modules_to_patch = [] - from _pydev_imps._pydev_saved_modules import thread as _thread + try: + import thread as _thread + except: + import _thread threading_modules_to_patch.append(_thread) return threading_modules_to_patch diff --git a/python/helpers/pydev/pydevd.py b/python/helpers/pydev/pydevd.py index 5c608e335704..e25be084dd9d 100644 --- a/python/helpers/pydev/pydevd.py +++ b/python/helpers/pydev/pydevd.py @@ -844,6 +844,7 @@ class PyDB: def patch_threads(self): try: # not available in jython! + import threading threading.settrace(self.trace_dispatch) # for all future threads except: pass