diff options
Diffstat (limited to 'python/helpers/pydev/pydev_monkey.py')
-rw-r--r-- | python/helpers/pydev/pydev_monkey.py | 44 |
1 files changed, 26 insertions, 18 deletions
diff --git a/python/helpers/pydev/pydev_monkey.py b/python/helpers/pydev/pydev_monkey.py index 2b12ed27522c..d92378ed0ee1 100644 --- a/python/helpers/pydev/pydev_monkey.py +++ b/python/helpers/pydev/pydev_monkey.py @@ -392,40 +392,42 @@ def patch_new_process_functions_with_warning(): class _NewThreadStartupWithTrace: - def __init__(self, original_func): + def __init__(self, original_func, args, kwargs): self.original_func = original_func + self.args = args + self.kwargs = kwargs - def __call__(self, *args, **kwargs): + def __call__(self): from pydevd_comm import GetGlobalDebugger global_debugger = GetGlobalDebugger() if global_debugger is not None: global_debugger.SetTrace(global_debugger.trace_dispatch) - return self.original_func(*args, **kwargs) + return self.original_func(*self.args, **self.kwargs) class _NewThreadStartupWithoutTrace: - def __init__(self, original_func): + def __init__(self, original_func, args, kwargs): self.original_func = original_func + self.args = args + self.kwargs = kwargs - def __call__(self, *args, **kwargs): - return self.original_func(*args, **kwargs) + def __call__(self): + return self.original_func(*self.args, **self.kwargs) _UseNewThreadStartup = _NewThreadStartupWithTrace -def _get_threading_modules(): - threading_modules = [] - from _pydev_imps import _pydev_thread - threading_modules.append(_pydev_thread) +def _get_threading_modules_to_patch(): + threading_modules_to_patch = [] try: import thread as _thread - threading_modules.append(_thread) + threading_modules_to_patch.append(_thread) except: import _thread - threading_modules.append(_thread) - return threading_modules + threading_modules_to_patch.append(_thread) + return threading_modules_to_patch -threading_modules = _get_threading_modules() +threading_modules_to_patch = _get_threading_modules_to_patch() @@ -439,12 +441,12 @@ def patch_thread_module(thread): class ClassWithPydevStartNewThread: - def pydev_start_new_thread(self, function, args, kwargs={}): + def pydev_start_new_thread(self, function, args=(), kwargs={}): ''' We need to replace the original thread.start_new_thread with this function so that threads started through it and not through the threading module are properly traced. ''' - return _original_start_new_thread(_UseNewThreadStartup(function), args, kwargs) + return _original_start_new_thread(_UseNewThreadStartup(function, args, kwargs), ()) # This is a hack for the situation where the thread.start_new_thread is declared inside a class, such as the one below # class F(object): @@ -465,11 +467,11 @@ def patch_thread_module(thread): pass def patch_thread_modules(): - for t in threading_modules: + for t in threading_modules_to_patch: patch_thread_module(t) def undo_patch_thread_modules(): - for t in threading_modules: + for t in threading_modules_to_patch: try: t.start_new_thread = t._original_start_new_thread except: @@ -494,3 +496,9 @@ def enable_trace_thread_modules(): ''' global _UseNewThreadStartup _UseNewThreadStartup = _NewThreadStartupWithTrace + +def get_original_start_new_thread(threading_module): + try: + return threading_module._original_start_new_thread + except: + return threading_module.start_new_thread |