File tree Expand file tree Collapse file tree 1 file changed +34
-1
lines changed
Expand file tree Collapse file tree 1 file changed +34
-1
lines changed Original file line number Diff line number Diff line change 66import gc
77import os
88import types
9+ import tempfile
10+ import subprocess
911
1012import _opcode
1113
1214from test .support import (script_helper , requires_specialization ,
1315 import_helper , Py_GIL_DISABLED , requires_jit_enabled ,
14- reset_code )
16+ reset_code , requires_subprocess )
1517
1618_testinternalcapi = import_helper .import_module ("_testinternalcapi" )
1719
@@ -2660,7 +2662,38 @@ def f():
26602662
26612663 f ()
26622664
2665+ @requires_subprocess ()
2666+ def test_interpreter_finalization_with_generator_alive (self ):
2667+ code = textwrap .dedent ("""
2668+ import sys
2669+ def simple_for():
2670+ for x in (1, 2):
2671+ x
26632672
2673+ def gen():
2674+ try:
2675+ yield
2676+ except:
2677+ simple_for()
2678+
2679+ sys.settrace(lambda *args: None)
2680+ simple_for()
2681+ g = gen()
2682+ next(g)
2683+ print("finished")
2684+ """ )
2685+
2686+ tmp = tempfile .NamedTemporaryFile (delete = False , suffix = '.py' )
2687+ tmp .write (code .encode ('utf-8' ))
2688+ tmp .close ()
2689+ try :
2690+ p = subprocess .Popen ([sys .executable , tmp .name ], stdout = subprocess .PIPE , stderr = subprocess .STDOUT )
2691+ p .wait ()
2692+ out = p .stdout .read ()
2693+ finally :
2694+ os .remove (tmp .name )
2695+ p .stdout .close ()
2696+ self .assertEqual (b"finished\n " , out )
26642697
26652698def global_identity (x ):
26662699 return x
You can’t perform that action at this time.
0 commit comments