summaryrefslogtreecommitdiffstats
path: root/Lib/test/support
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2023-12-12 18:06:06 (GMT)
committerGitHub <noreply@github.com>2023-12-12 18:06:06 (GMT)
commit9898e6104171dcdd88b32776e69ca2cddf515e63 (patch)
treeffc33f1653dbbb7737a18bdf3db474b1b5203a89 /Lib/test/support
parenta49b427b0265c415d9089da0be39f4b5ccd1f15f (diff)
downloadcpython-9898e6104171dcdd88b32776e69ca2cddf515e63.zip
cpython-9898e6104171dcdd88b32776e69ca2cddf515e63.tar.gz
cpython-9898e6104171dcdd88b32776e69ca2cddf515e63.tar.bz2
gh-76785: Add Interpreter.prepare_main() (gh-113021)
This is one of the last pieces to get test.support.interpreters in sync with PEP 734.
Diffstat (limited to 'Lib/test/support')
-rw-r--r--Lib/test/support/interpreters/__init__.py16
1 files changed, 12 insertions, 4 deletions
diff --git a/Lib/test/support/interpreters/__init__.py b/Lib/test/support/interpreters/__init__.py
index 2d6376d..9cd1c3d 100644
--- a/Lib/test/support/interpreters/__init__.py
+++ b/Lib/test/support/interpreters/__init__.py
@@ -130,7 +130,15 @@ class Interpreter:
"""
return _interpreters.destroy(self._id)
- def exec_sync(self, code, /, channels=None):
+ def prepare_main(self, ns=None, /, **kwargs):
+ """Bind the given values into the interpreter's __main__.
+
+ The values must be shareable.
+ """
+ ns = dict(ns, **kwargs) if ns is not None else kwargs
+ _interpreters.set___main___attrs(self._id, ns)
+
+ def exec_sync(self, code, /):
"""Run the given source code in the interpreter.
This is essentially the same as calling the builtin "exec"
@@ -148,13 +156,13 @@ class Interpreter:
that time, the previous interpreter is allowed to run
in other threads.
"""
- excinfo = _interpreters.exec(self._id, code, channels)
+ excinfo = _interpreters.exec(self._id, code)
if excinfo is not None:
raise ExecFailure(excinfo)
- def run(self, code, /, channels=None):
+ def run(self, code, /):
def task():
- self.exec_sync(code, channels=channels)
+ self.exec_sync(code)
t = threading.Thread(target=task)
t.start()
return t