|
1 | 1 | import contextlib |
2 | 2 | import itertools |
| 3 | +import subprocess |
3 | 4 | import sys |
4 | 5 | import textwrap |
5 | 6 | import unittest |
|
9 | 10 |
|
10 | 11 | import _opcode |
11 | 12 |
|
12 | | -from test.support import (script_helper, requires_specialization, |
| 13 | +from test.support import (SHORT_TIMEOUT, script_helper, requires_specialization, |
13 | 14 | import_helper, Py_GIL_DISABLED, requires_jit_enabled, |
14 | 15 | reset_code) |
15 | 16 |
|
@@ -5994,6 +5995,51 @@ def __init__(self, name): |
5994 | 5995 | PYTHON_JIT_SIDE_EXIT_INITIAL_VALUE="1") |
5995 | 5996 | self.assertEqual(result[0].rc, 0, result) |
5996 | 5997 |
|
| 5998 | + def test_side_exit_to_executor_makes_progress(self): |
| 5999 | + script = textwrap.dedent(""" |
| 6000 | + classes = [] |
| 6001 | +
|
| 6002 | + def make_iter(): |
| 6003 | + class It: |
| 6004 | + def __init__(self): |
| 6005 | + self.i = 0 |
| 6006 | +
|
| 6007 | + def __iter__(self): |
| 6008 | + return self |
| 6009 | +
|
| 6010 | + def __next__(self): |
| 6011 | + self.i += 1 |
| 6012 | + if self.i > 1000: |
| 6013 | + raise StopIteration |
| 6014 | + return self.i |
| 6015 | +
|
| 6016 | + classes.append(It) |
| 6017 | + return It() |
| 6018 | +
|
| 6019 | + def f(n): |
| 6020 | + for outer in range(n): |
| 6021 | + for x in make_iter(): |
| 6022 | + pass |
| 6023 | +
|
| 6024 | + f(200) |
| 6025 | + """) |
| 6026 | + env = os.environ.copy() |
| 6027 | + env.update({ |
| 6028 | + "PYTHON_JIT": "1", |
| 6029 | + "PYTHON_JIT_SIDE_EXIT_INITIAL_VALUE": "1", |
| 6030 | + }) |
| 6031 | + try: |
| 6032 | + result = subprocess.run( |
| 6033 | + [sys.executable, "-X", "faulthandler", "-c", script], |
| 6034 | + stdout=subprocess.PIPE, |
| 6035 | + stderr=subprocess.PIPE, |
| 6036 | + env=env, |
| 6037 | + timeout=SHORT_TIMEOUT, |
| 6038 | + ) |
| 6039 | + except subprocess.TimeoutExpired as exc: |
| 6040 | + self.fail(f"subprocess timed out: {exc}") |
| 6041 | + self.assertEqual(result.returncode, 0, result) |
| 6042 | + |
5997 | 6043 | def test_for_iter_gen_cleared_frame_does_not_crash(self): |
5998 | 6044 | # See: https://github.com/python/cpython/issues/145197 |
5999 | 6045 | result = script_helper.run_python_until_end('-c', textwrap.dedent(""" |
|
0 commit comments