diff options
author | Eric Snow <ericsnowcurrently@gmail.com> | 2023-10-06 17:52:22 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-06 17:52:22 -0600 |
commit | 92ca90b7629c070ebc3b08e6f03db0bb552634e3 (patch) | |
tree | a59ee0bebd542d61c7a243191617aebbe9f65ab7 /Lib/test/support/interpreters.py | |
parent | de1052245f67d5c5a5dbb4f39449f7687f58fd78 (diff) | |
download | cpython-92ca90b7629c070ebc3b08e6f03db0bb552634e3.tar.gz cpython-92ca90b7629c070ebc3b08e6f03db0bb552634e3.zip |
gh-76785: Support Running Some Functions in Subinterpreters (gh-110251)
This specifically refers to `test.support.interpreters.Interpreter.run()`.
Diffstat (limited to 'Lib/test/support/interpreters.py')
-rw-r--r-- | Lib/test/support/interpreters.py | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/Lib/test/support/interpreters.py b/Lib/test/support/interpreters.py index 3b501614bc4..5aba36950f0 100644 --- a/Lib/test/support/interpreters.py +++ b/Lib/test/support/interpreters.py @@ -91,12 +91,26 @@ class Interpreter: """ return _interpreters.destroy(self._id) + # XXX Rename "run" to "exec"? def run(self, src_str, /, *, channels=None): """Run the given source code in the interpreter. - This blocks the current Python thread until done. + This is essentially the same as calling the builtin "exec" + with this interpreter, using the __dict__ of its __main__ + module as both globals and locals. + + There is no return value. + + If the code raises an unhandled exception then a RunFailedError + is raised, which summarizes the unhandled exception. The actual + exception is discarded because objects cannot be shared between + interpreters. + + This blocks the current Python thread until done. During + that time, the previous interpreter is allowed to run + in other threads. """ - _interpreters.run_string(self._id, src_str, channels) + _interpreters.exec(self._id, src_str, channels) def create_channel(): |