Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
76a7d7b
Make Interpreter() idempotent.
ericsnowcurrently Nov 28, 2023
57a3c19
Interpreters are always isolated.
ericsnowcurrently Nov 28, 2023
747e542
interp.id is always int.
ericsnowcurrently Nov 28, 2023
0ed9fb0
Add InterpreterNotFoundError.
ericsnowcurrently Dec 1, 2023
98f9cf3
Stop using InterpreterID in _interpreters.
ericsnowcurrently Dec 1, 2023
0277878
Fix Interpreter.__repr__().
ericsnowcurrently Nov 28, 2023
59c8227
.run() -> .exec_sync()
ericsnowcurrently Nov 28, 2023
fa132a2
RunFailedError -> ExecFailure
ericsnowcurrently Nov 28, 2023
644efa5
Add Interpreter.run().
ericsnowcurrently Nov 28, 2023
abf2aa8
Make the interpreters module a package.
ericsnowcurrently Dec 1, 2023
8ca303f
Add interpreters.Queue.
ericsnowcurrently Nov 28, 2023
8b97373
Add memoryview XID with _xxsubinterpreters import.
ericsnowcurrently Dec 11, 2023
cc20f1f
Update CODEOWNERS.
ericsnowcurrently Dec 11, 2023
cb0a605
Ignore static builtin exception types.
ericsnowcurrently Dec 11, 2023
62a9bac
Make CODEOWNERS more specific.
ericsnowcurrently Dec 11, 2023
6c71018
Fix submodule names.
ericsnowcurrently Dec 11, 2023
13a44e3
Use interpreters.__getattr__() for submodule aliases.
ericsnowcurrently Dec 7, 2023
c9d15d2
Fix InterpreterIDTests.
ericsnowcurrently Dec 11, 2023
1c76c4a
LONG_LONG_MAX -> LLONG_MAX
ericsnowcurrently Dec 11, 2023
cfae15f
Fix Interpreter.run().
ericsnowcurrently Dec 11, 2023
3f98ce1
Use exec_sync() in test_sys.
ericsnowcurrently Dec 11, 2023
f8b1685
Fix test_capi.
ericsnowcurrently Dec 11, 2023
0b34a83
Fix test_importlib.
ericsnowcurrently Dec 12, 2023
68faf1a
Fix test_import.
ericsnowcurrently Dec 12, 2023
d161f76
Fix test_threading.
ericsnowcurrently Dec 12, 2023
778276f
Fix TestInterpreterRun.
ericsnowcurrently Dec 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
.run() -> .exec_sync()
  • Loading branch information
ericsnowcurrently committed Dec 4, 2023
commit 59c8227c72e67dde383280010e05b67b65ccf6b2
5 changes: 2 additions & 3 deletions Lib/test/support/interpreters.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ def close(self):
"""
return _interpreters.destroy(self._id)

# XXX Rename "run" to "exec"?
def run(self, src_str, /, channels=None):
def exec_sync(self, code, /, channels=None):
"""Run the given source code in the interpreter.

This is essentially the same as calling the builtin "exec"
Expand All @@ -141,7 +140,7 @@ def run(self, src_str, /, channels=None):
that time, the previous interpreter is allowed to run
in other threads.
"""
excinfo = _interpreters.exec(self._id, src_str, channels)
excinfo = _interpreters.exec(self._id, code, channels)
if excinfo is not None:
raise RunFailedError(excinfo)

Expand Down
43 changes: 22 additions & 21 deletions Lib/test/test_interpreters.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ def clean_up_interpreters():
def _run_output(interp, request, channels=None):
script, rpipe = _captured_script(request)
with rpipe:
interp.run(script, channels=channels)
interp.exec_sync(script, channels=channels)
return rpipe.read()


@contextlib.contextmanager
def _running(interp):
r, w = os.pipe()
def run():
interp.run(dedent(f"""
interp.exec_sync(dedent(f"""
# wait for "signal"
with open({r}) as rpipe:
rpipe.read()
Expand Down Expand Up @@ -328,7 +328,7 @@ def test_subinterpreter(self):
def test_finished(self):
r, w = self.pipe()
interp = interpreters.create()
interp.run(f"""if True:
interp.exec_sync(f"""if True:
import os
os.write({w}, b'x')
""")
Expand Down Expand Up @@ -360,7 +360,7 @@ def test_with_only_background_threads(self):
FINISHED = b'F'

interp = interpreters.create()
interp.run(f"""if True:
interp.exec_sync(f"""if True:
import os
import threading

Expand All @@ -374,7 +374,7 @@ def task():
self.assertFalse(interp.is_running())

os.write(w_thread, DONE)
interp.run('t.join()')
interp.exec_sync('t.join()')
self.assertEqual(os.read(r_interp, 1), FINISHED)


Expand Down Expand Up @@ -441,7 +441,7 @@ def test_from_sibling(self):
interp2 = interpreters.create()
self.assertEqual(set(interpreters.list_all()),
{main, interp1, interp2})
interp1.run(dedent(f"""
interp1.exec_sync(dedent(f"""
from test.support import interpreters
interp2 = interpreters.Interpreter({interp2.id})
interp2.close()
Expand Down Expand Up @@ -475,7 +475,7 @@ def test_subthreads_still_running(self):
FINISHED = b'F'

interp = interpreters.create()
interp.run(f"""if True:
interp.exec_sync(f"""if True:
import os
import threading
import time
Expand Down Expand Up @@ -506,22 +506,22 @@ def test_success(self):
interp = interpreters.create()
script, file = _captured_script('print("it worked!", end="")')
with file:
interp.run(script)
interp.exec_sync(script)
out = file.read()

self.assertEqual(out, 'it worked!')

def test_failure(self):
interp = interpreters.create()
with self.assertRaises(interpreters.RunFailedError):
interp.run('raise Exception')
interp.exec_sync('raise Exception')

def test_in_thread(self):
interp = interpreters.create()
script, file = _captured_script('print("it worked!", end="")')
with file:
def f():
interp.run(script)
interp.exec_sync(script)

t = threading.Thread(target=f)
t.start()
Expand All @@ -547,7 +547,7 @@ def test_fork(self):
with open('{file.name}', 'w', encoding='utf-8') as out:
out.write('{expected}')
""")
interp.run(script)
interp.exec_sync(script)

file.seek(0)
content = file.read()
Expand All @@ -558,17 +558,17 @@ def test_already_running(self):
interp = interpreters.create()
with _running(interp):
with self.assertRaises(RuntimeError):
interp.run('print("spam")')
interp.exec_sync('print("spam")')

def test_bad_script(self):
interp = interpreters.create()
with self.assertRaises(TypeError):
interp.run(10)
interp.exec_sync(10)

def test_bytes_for_script(self):
interp = interpreters.create()
with self.assertRaises(TypeError):
interp.run(b'print("spam")')
interp.exec_sync(b'print("spam")')

def test_with_background_threads_still_running(self):
r_interp, w_interp = self.pipe()
Expand All @@ -579,7 +579,7 @@ def test_with_background_threads_still_running(self):
FINISHED = b'F'

interp = interpreters.create()
interp.run(f"""if True:
interp.exec_sync(f"""if True:
import os
import threading

Expand All @@ -591,17 +591,18 @@ def task():
t.start()
os.write({w_interp}, {RAN!r})
""")
interp.run(f"""if True:
interp.exec_sync(f"""if True:
os.write({w_interp}, {RAN!r})
""")

os.write(w_thread, DONE)
interp.run('t.join()')
interp.exec_sync('t.join()')
self.assertEqual(os.read(r_interp, 1), RAN)
self.assertEqual(os.read(r_interp, 1), RAN)
self.assertEqual(os.read(r_interp, 1), FINISHED)

# test_xxsubinterpreters covers the remaining Interpreter.run() behavior.
# test_xxsubinterpreters covers the remaining
# Interpreter.exec_sync() behavior.


class StressTests(TestBase):
Expand Down Expand Up @@ -737,7 +738,7 @@ def test_sys_path_0(self):
orig = sys.path[0]

interp = interpreters.create()
interp.run(f"""if True:
interp.exec_sync(f"""if True:
import json
import sys
print(json.dumps({{
Expand Down Expand Up @@ -958,7 +959,7 @@ def test_send_recv_main(self):

def test_send_recv_same_interpreter(self):
interp = interpreters.create()
interp.run(dedent("""
interp.exec_sync(dedent("""
from test.support import interpreters
r, s = interpreters.create_channel()
orig = b'spam'
Expand Down Expand Up @@ -1031,7 +1032,7 @@ def test_send_recv_nowait_main_with_default(self):

def test_send_recv_nowait_same_interpreter(self):
interp = interpreters.create()
interp.run(dedent("""
interp.exec_sync(dedent("""
from test.support import interpreters
r, s = interpreters.create_channel()
orig = b'spam'
Expand Down