From bde963553ee9a7d241a50be2f84b6f20ff09ba83 Mon Sep 17 00:00:00 2001 From: Mick Phillips Date: Wed, 15 Jul 2026 17:10:04 -0700 Subject: [PATCH] Fix traceback in threads when SetTrace used. Testing === The following script returns normamly, where previously it encountered: `ValueError: call stack is not deep enough`. ``` import sys import threading import typing def tracer(frame, event, arg): return tracer def do_check(): isinstance(None, typing.Iterable) sys.settrace(tracer) t = threading.Thread(target=do_check) t.start() t.join() ``` --- src/core/IronPython/Runtime/PythonContext.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/IronPython/Runtime/PythonContext.cs b/src/core/IronPython/Runtime/PythonContext.cs index 32907cec8..ef3dc9f79 100644 --- a/src/core/IronPython/Runtime/PythonContext.cs +++ b/src/core/IronPython/Runtime/PythonContext.cs @@ -3848,9 +3848,9 @@ public PythonTracebackListenersDispatcher(PythonContext parent) { void Debugging.ITraceCallback.OnTraceEvent(Debugging.TraceEventKind kind, string name, string sourceFileName, SourceSpan sourceSpan, Func> scopeCallback, object payload, object customPayload) { var listener = _parent._tracebackListeners.Value; - if (listener == null && _parent.PythonOptions.Tracing) { - // If tracing without sys.set_trace() is enabled, we need to register a dummy traceback listener, - // because of the FunctionStack handling done there. + if (listener == null && (_parent.PythonOptions.Tracing || _parent._tracebackListenersCount > 0)) { + // If tracing is enabled (globally or via SetTrace on any thread), we need to register a dummy + // traceback listener for this thread, because of the FunctionStack handling done there. _parent._tracebackListeners.Value = listener = new PythonTracebackListener(_parent, null); }