Skip to content

Commit c3e987b

Browse files
pythonGH-96636: Remove all uses of NOTRACE_DISPATCH (pythonGH-96643)
Co-authored-by: Brandt Bucher <brandtbucher@gmail.com> (cherry picked from commit aa3b4cf)
1 parent 99919d4 commit c3e987b

File tree

3 files changed

+108
-59
lines changed

3 files changed

+108
-59
lines changed

Lib/test/test_dynamic.py

+44
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Test the most dynamic corner cases of Python's runtime semantics.
22

33
import builtins
4+
import sys
45
import unittest
56

67
from test.support import swap_item, swap_attr
@@ -146,5 +147,48 @@ def __missing__(self, key):
146147
for _ in range(30):
147148
self.assertEqual(sum_1000(), expected)
148149

150+
151+
class TestTracing(unittest.TestCase):
152+
153+
def setUp(self):
154+
self.addCleanup(sys.settrace, sys.gettrace())
155+
sys.settrace(None)
156+
157+
def test_after_specialization(self):
158+
159+
def trace(frame, event, arg):
160+
return trace
161+
162+
turn_on_trace = False
163+
164+
class C:
165+
def __init__(self, x):
166+
self.x = x
167+
def __del__(self):
168+
if turn_on_trace:
169+
sys.settrace(trace)
170+
171+
def f():
172+
# LOAD_GLOBAL[_BUILTIN] immediately follows the call to C.__del__
173+
C(0).x, len
174+
175+
def g():
176+
# BINARY_SUSCR[_LIST_INT] immediately follows the call to C.__del__
177+
[0][C(0).x]
178+
179+
def h():
180+
# BINARY_OP[_ADD_INT] immediately follows the call to C.__del__
181+
0 + C(0).x
182+
183+
for func in (f, g, h):
184+
with self.subTest(func.__name__):
185+
for _ in range(58):
186+
func()
187+
turn_on_trace = True
188+
func()
189+
sys.settrace(None)
190+
turn_on_trace = False
191+
192+
149193
if __name__ == "__main__":
150194
unittest.main()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Ensure that tracing, ``sys.setrace()``, is turned on immediately. In
2+
pre-release versions of 3.11, some tracing events might have been lost when
3+
turning on tracing in a ``__del__`` method or interrupt.

0 commit comments

Comments
 (0)