IDEA-CR-61812: Fix issue when pydevd threads are been traced and print warning if it has happened

(cherry picked from commit 9dfb2b4c903c5fd3d6d903fc4f2171c3738667b9)

GitOrigin-RevId: 7bf235aeb854030823162a3ba5a778e46f37c3b2
This commit is contained in:
Andrey Lisin
2020-04-22 13:09:37 +03:00
committed by intellij-monorepo-bot
parent 345a40561e
commit 9629463526
2 changed files with 7 additions and 8 deletions

View File

@@ -212,6 +212,7 @@ class PyDBDaemonThread(threading.Thread):
PyCore.Py.setSystemState(ss)
self._stop_trace()
self._warn_pydevd_thread_is_traced()
self._on_run()
except:
if sys is not None and traceback is not None:
@@ -233,6 +234,10 @@ class PyDBDaemonThread(threading.Thread):
if self.pydev_do_not_trace:
pydevd_tracing.SetTrace(None) # no debugging on this thread
def _warn_pydevd_thread_is_traced(self):
if sys.gettrace():
pydevd_log(1, "The debugger thread '%s' is traced which may lead to debugging performance issues." % self.__class__.__name__)
def mark_as_pydevd_daemon_thread(thread):
thread.pydev_do_not_trace = True

View File

@@ -73,24 +73,17 @@ def _internal_set_trace(tracing_func):
def SetTrace(tracing_func):
if TracingFunctionHolder._original_tracing is None:
#This may happen before replace_sys_set_trace_func is called.
# This may happen before replace_sys_set_trace_func is called.
sys.settrace(tracing_func)
return
current_thread = threading.currentThread()
do_not_trace_before = getattr(current_thread, 'pydev_do_not_trace', None)
if do_not_trace_before:
return
try:
TracingFunctionHolder._lock.acquire()
current_thread.pydev_do_not_trace = True # avoid settrace reentering
TracingFunctionHolder._warn = False
_internal_set_trace(tracing_func)
TracingFunctionHolder._warn = True
finally:
TracingFunctionHolder._lock.release()
current_thread.pydev_do_not_trace = do_not_trace_before
def replace_sys_set_trace_func():
@@ -98,6 +91,7 @@ def replace_sys_set_trace_func():
TracingFunctionHolder._original_tracing = sys.settrace
sys.settrace = _internal_set_trace
def restore_sys_set_trace_func():
if TracingFunctionHolder._original_tracing is not None:
sys.settrace = TracingFunctionHolder._original_tracing