File tree Expand file tree Collapse file tree 3 files changed +19
-0
lines changed
Lib/test/test_free_threading
Misc/NEWS.d/next/Core_and_Builtins Expand file tree Collapse file tree 3 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -270,6 +270,21 @@ def mutate():
270270
271271 do_race (set_value , mutate )
272272
273+ def test_racing_recursion_limit (self ):
274+ def something_recursive ():
275+ def count (n ):
276+ if n > 0 :
277+ return count (n - 1 ) + 1
278+ return 0
279+
280+ count (50 )
281+
282+ def set_recursion_limit ():
283+ for limit in range (100 , 200 ):
284+ sys .setrecursionlimit (limit )
285+
286+ do_race (something_recursive , set_recursion_limit )
287+
273288
274289if __name__ == "__main__" :
275290 unittest .main ()
Original file line number Diff line number Diff line change 1+ Fix a crash when setting the recursion limit while other threads are active
2+ on the :term: `free threaded <free threading> ` build.
Original file line number Diff line number Diff line change @@ -294,13 +294,15 @@ void
294294Py_SetRecursionLimit (int new_limit )
295295{
296296 PyInterpreterState * interp = _PyInterpreterState_GET ();
297+ _PyEval_StopTheWorld (interp );
297298 interp -> ceval .recursion_limit = new_limit ;
298299 _Py_FOR_EACH_TSTATE_BEGIN (interp , p ) {
299300 int depth = p -> py_recursion_limit - p -> py_recursion_remaining ;
300301 p -> py_recursion_limit = new_limit ;
301302 p -> py_recursion_remaining = new_limit - depth ;
302303 }
303304 _Py_FOR_EACH_TSTATE_END (interp );
305+ _PyEval_StartTheWorld (interp );
304306}
305307
306308/* The function _Py_EnterRecursiveCallTstate() only calls _Py_CheckRecursiveCall()
You can’t perform that action at this time.
0 commit comments