File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -2660,6 +2660,25 @@ def f():
26602660
26612661 f ()
26622662
2663+ def test_interpreter_finalization_with_generator_alive (self ):
2664+ script_helper .assert_python_ok ("-c" , textwrap .dedent ("""
2665+ import sys
2666+ t = tuple(range(%d))
2667+ def simple_for():
2668+ for x in t:
2669+ x
2670+
2671+ def gen():
2672+ try:
2673+ yield
2674+ except:
2675+ simple_for()
2676+
2677+ sys.settrace(lambda *args: None)
2678+ simple_for()
2679+ g = gen()
2680+ next(g)
2681+ """ % _testinternalcapi .SPECIALIZATION_THRESHOLD ))
26632682
26642683
26652684def global_identity (x ):
Original file line number Diff line number Diff line change @@ -118,7 +118,13 @@ _PyOptimizer_Optimize(
118118{
119119 _PyStackRef * stack_pointer = frame -> stackpointer ;
120120 PyInterpreterState * interp = _PyInterpreterState_GET ();
121- assert (interp -> jit );
121+ if (!interp -> jit ) {
122+ // gh-140936: It is possible that interp->jit will become false during
123+ // interpreter finalization. However, the specialized JUMP_BACKWARD_JIT
124+ // instruction may still be present. In this case, we should
125+ // return immediately without optimization.
126+ return 0 ;
127+ }
122128 assert (!interp -> compiling );
123129#ifndef Py_GIL_DISABLED
124130 interp -> compiling = true;
You can’t perform that action at this time.
0 commit comments