Skip to content

Commit bd4e1a6

Browse files
maxbachmannrchiodo
andauthored
avoid strong reference to exceptions during unwind (#2008)
* avoid strong reference to exceptions during unwind * update cython files * fix getattr * remove comment * avoid side effect from overloaded getattr/setattr * Generate cython on Windows * Put back non sys monitoring cython --------- Co-authored-by: Rich Chiodo false <rchiodo@microsoft.com>
1 parent 880b083 commit bd4e1a6

File tree

3 files changed

+3461
-3248
lines changed

3 files changed

+3461
-3248
lines changed

src/debugpy/_vendored/pydevd/_pydevd_sys_monitoring/_pydevd_sys_monitoring.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,13 @@ def _get_bootstrap_frame(depth: int) -> Tuple[Optional[FrameType], bool]:
169169
return f_bootstrap, is_bootstrap_frame_internal
170170

171171

172+
class UnhandledExceptionTag:
173+
"""
174+
Tag that is attached to exceptions so we can compare the instance without a strong reference
175+
See issue https://github.com/microsoft/debugpy/issues/1999
176+
"""
177+
178+
172179
# fmt: off
173180
# IFDEF CYTHON
174181
# cdef _get_unhandled_exception_frame(exc, int depth):
@@ -177,12 +184,16 @@ def _get_unhandled_exception_frame(exc, depth: int) -> Optional[FrameType]:
177184
# ENDIF
178185
# fmt: on
179186
try:
180-
# Unhandled frame has to be from the same exception.
181-
if _thread_local_info.f_unhandled_exc is exc:
187+
tag = exc.__dict__.setdefault('__pydevd_tag__', UnhandledExceptionTag())
188+
except:
189+
tag = exc
190+
191+
try:
192+
if _thread_local_info.f_unhandled_exc_tag is tag:
182193
return _thread_local_info.f_unhandled_frame
183194
else:
184195
del _thread_local_info.f_unhandled_frame
185-
del _thread_local_info.f_unhandled_exc
196+
del _thread_local_info.f_unhandled_exc_tag
186197
raise AttributeError('Not the same exception')
187198
except:
188199
f_unhandled = _getframe(depth)
@@ -222,7 +233,7 @@ def _get_unhandled_exception_frame(exc, depth: int) -> Optional[FrameType]:
222233

223234
if f_unhandled is not None:
224235
_thread_local_info.f_unhandled_frame = f_unhandled
225-
_thread_local_info.f_unhandled_exc = exc
236+
_thread_local_info.f_unhandled_exc_tag = tag
226237
return _thread_local_info.f_unhandled_frame
227238

228239
return f_unhandled

0 commit comments

Comments
 (0)