diff --git a/Lib/test/crashers/trace_at_recursion_limit.py b/Lib/test/crashers/trace_at_recursion_limit.py deleted file mode 100644 index acd863f5509c49b..000000000000000 --- a/Lib/test/crashers/trace_at_recursion_limit.py +++ /dev/null @@ -1,27 +0,0 @@ -""" -From http://bugs.python.org/issue6717 - -A misbehaving trace hook can trigger a segfault by exceeding the recursion -limit. -""" -import sys - - -def x(): - pass - -def g(*args): - if True: # change to True to crash interpreter - try: - x() - except: - pass - return g - -def f(): - print(sys.getrecursionlimit()) - f() - -sys.settrace(g) - -f() diff --git a/Lib/test/test_sys_settrace.py b/Lib/test/test_sys_settrace.py index a5e7bbbfad5ffca..6ba9fa355f75b5a 100644 --- a/Lib/test/test_sys_settrace.py +++ b/Lib/test/test_sys_settrace.py @@ -3047,6 +3047,26 @@ def setUp(self): self.addCleanup(sys.settrace, sys.gettrace()) sys.settrace(None) + def test_trace_at_recursion_limit(self): + def recurse(n): + if n: + recurse(n - 1) + + caught_in_trace = False + + def trace(frame, event, arg): + nonlocal caught_in_trace + try: + recurse(0) + except RecursionError: + caught_in_trace = True + return trace + + with support.infinite_recursion(25), self.assertRaises(RecursionError): + sys.settrace(trace) + recurse(40) + self.assertTrue(caught_in_trace) + def test_reentrancy(self): def foo(*args): ...