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():
270
270
271
271
do_race (set_value , mutate )
272
272
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
+
273
288
274
289
if __name__ == "__main__" :
275
290
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
294
294
Py_SetRecursionLimit (int new_limit )
295
295
{
296
296
PyInterpreterState * interp = _PyInterpreterState_GET ();
297
+ _PyEval_StopTheWorld (interp );
297
298
interp -> ceval .recursion_limit = new_limit ;
298
299
_Py_FOR_EACH_TSTATE_BEGIN (interp , p ) {
299
300
int depth = p -> py_recursion_limit - p -> py_recursion_remaining ;
300
301
p -> py_recursion_limit = new_limit ;
301
302
p -> py_recursion_remaining = new_limit - depth ;
302
303
}
303
304
_Py_FOR_EACH_TSTATE_END (interp );
305
+ _PyEval_StartTheWorld (interp );
304
306
}
305
307
306
308
/* The function _Py_EnterRecursiveCallTstate() only calls _Py_CheckRecursiveCall()
You can’t perform that action at this time.
0 commit comments