Skip to content

Commit 937b990

Browse files
Test added
1 parent cc1f1e9 commit 937b990

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

Lib/test/test_capi/test_opt.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
import gc
77
import os
88
import types
9+
import tempfile
10+
import subprocess
911

1012
import _opcode
1113

1214
from 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

26652698
def global_identity(x):
26662699
return x

0 commit comments

Comments
 (0)