Prevent pydevd_tracing.SetTrace from being reentered
As it causes a deadlock on a non-recursive lock
+from contextlib import contextmanager
+
from _pydevd_bundle.pydevd_constants import get_frame
from _pydev_imps._pydev_saved_modules import thread, threading
@@ -67,6 +69,20 @@ def _internal_set_trace(tracing_func):
TracingFunctionHolder._original_tracing(tracing_func)
+@contextmanager
+def _do_not_trace_ctx():
+ current_thread = threading.currentThread()
+ do_not_trace_before = getattr(current_thread, 'pydev_do_not_trace', None)
+ if do_not_trace_before:
+ yield
+ return
+ current_thread.pydev_do_not_trace = True
+ try:
+ yield
+ finally:
+ current_thread.pydev_do_not_trace = do_not_trace_before
+
+
def SetTrace(tracing_func, frame_eval_func=None, dummy_tracing_func=None):
if tracing_func is not None and frame_eval_func is not None:
# There is no need to set tracing function if frame evaluation is available
@@ -78,6 +94,7 @@ def SetTrace(tracing_func, frame_eval_func=None, dummy_tracing_func=None):
sys.settrace(tracing_func)
return
+ with _do_not_trace_ctx():
TracingFunctionHolder._lock.acquire()
try:
TracingFunctionHolder._warn = False
