mirror of
https://github.com/python/cpython.git
synced 2025-09-08 18:01:44 +00:00
gh-76785: Update test.support.interpreters to Align With PEP 734 (gh-115566)
This brings the code under test.support.interpreters, and the corresponding extension modules, in line with recent updates to PEP 734. (Note: PEP 734 has not been accepted at this time. However, we are using an internal copy of the implementation in the test suite to exercise the existing subinterpreters feature.)
This commit is contained in:
parent
67c19e57b5
commit
e80abd57a8
11 changed files with 622 additions and 155 deletions
|
@ -4,8 +4,9 @@ import os.path
|
|||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import threading
|
||||
from textwrap import dedent
|
||||
import threading
|
||||
import types
|
||||
import unittest
|
||||
|
||||
from test import support
|
||||
|
@ -41,7 +42,7 @@ def _run_output(interp, request, init=None):
|
|||
with rpipe:
|
||||
if init:
|
||||
interp.prepare_main(init)
|
||||
interp.exec_sync(script)
|
||||
interp.exec(script)
|
||||
return rpipe.read()
|
||||
|
||||
|
||||
|
@ -49,7 +50,7 @@ def _run_output(interp, request, init=None):
|
|||
def _running(interp):
|
||||
r, w = os.pipe()
|
||||
def run():
|
||||
interp.exec_sync(dedent(f"""
|
||||
interp.exec(dedent(f"""
|
||||
# wait for "signal"
|
||||
with open({r}) as rpipe:
|
||||
rpipe.read()
|
||||
|
@ -84,6 +85,18 @@ class TestBase(unittest.TestCase):
|
|||
self.addCleanup(lambda: os_helper.rmtree(tempdir))
|
||||
return tempdir
|
||||
|
||||
@contextlib.contextmanager
|
||||
def captured_thread_exception(self):
|
||||
ctx = types.SimpleNamespace(caught=None)
|
||||
def excepthook(args):
|
||||
ctx.caught = args
|
||||
orig_excepthook = threading.excepthook
|
||||
threading.excepthook = excepthook
|
||||
try:
|
||||
yield ctx
|
||||
finally:
|
||||
threading.excepthook = orig_excepthook
|
||||
|
||||
def make_script(self, filename, dirname=None, text=None):
|
||||
if text:
|
||||
text = dedent(text)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue