8000 gh-76785: Handle Legacy Interpreters Properly by ericsnowcurrently · Pull Request #117490 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-76785: Handle Legacy Interpreters Properly #117490

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
Default to require_owned=False.
  • Loading branch information
ericsnowcurrently committed Apr 11, 2024
commit 55a1c3100ea2be8b8fbe53dbf3b3acab2c1faf92
2 changes: 1 addition & 1 deletion Lib/test/test__xxsubinterpreters.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ class IsRunningTests(TestBase):

def test_main(self):
main, *_ = _interpreters.get_main()
self.assertTrue(_interpreters.is_running(main, require_owned=False))
self.assertTrue(_interpreters.is_running(main))

@unittest.skip('Fails on FreeBSD')
def test_subinterpreter(self):
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_capi/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2428,7 +2428,7 @@ def new_interp(config):
expected = _interpreters.new_config('legacy')
expected.gil = 'own'
interpid, *_ = _interpreters.get_main()
config = _interpreters.get_config(interpid, require_owned=False)
config = _interpreters.get_config(interpid)
self.assert_ns_equal(config, expected)

with self.subTest('isolated'):
Expand Down
32 changes: 13 additions & 19 deletions Lib/test/test_interpreters/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1431,10 +1431,10 @@ def test_destroy(self):
with self.subTest('from C-API'):
interpid = _testinternalcapi.create_interpreter()
with self.assertRaisesRegex(InterpreterError, 'unrecognized'):
_interpreters.destroy(interpid)
_interpreters.destroy(interpid, require_owned=True)
self.assertTrue(
self.interp_exists(interpid))
_interpreters.destroy(interpid, require_owned=False)
_interpreters.destroy(interpid)
self.assertFalse(
self.interp_exists(interpid))

Expand All @@ -1446,7 +1446,7 @@ def test_get_config(self):
expected = _interpreters.new_config('legacy')
expected.gil = 'own'
interpid, *_ = _interpreters.get_main()
config = _interpreters.get_config(interpid, require_owned=False)
config = _interpreters.get_config(interpid)
self.assert_ns_equal(config, expected)

with self.subTest('isolated'):
Expand All @@ -1465,8 +1465,8 @@ def test_get_config(self):
orig = _interpreters.new_config('isolated')
with self.interpreter_from_capi(orig) as interpid:
with self.assertRaisesRegex(InterpreterError, 'unrecognized'):
_interpreters.get_config(interpid)
config = _interpreters.get_config(interpid, require_owned=False)
_interpreters.get_config(interpid, require_owned=True)
config = _interpreters.get_config(interpid)
self.assert_ns_equal(config, orig)

@requires_test_modules
Expand Down Expand Up @@ -1516,8 +1516,8 @@ def test_whence(self):
def test_is_running(self):
def check(interpid, expected):
with self.assertRaisesRegex(InterpreterError, 'unrecognized'):
_interpreters.is_running(interpid)
running = _interpreters.is_running(interpid, require_owned=False)
_interpreters.is_running(interpid, require_owned=True)
running = _interpreters.is_running(interpid)
self.assertIs(running, expected)

with self.subTest('from _interpreters (running)'):
Expand Down Expand Up @@ -1585,12 +1585,9 @@ def test_exec(self):
with self.subTest('from C-API'):
with self.interpreter_from_capi() as interpid:
with self.assertRaisesRegex(InterpreterError, 'unrecognized'):
_interpreters.exec(interpid, 'raise Exception("it worked!")')
exc = _interpreters.exec(
interpid,
'raise Exception("it worked!")',
require_owned=False,
)
_interpreters.exec(interpid, 'raise Exception("it worked!")',
require_owned=True)
exc = _interpreters.exec(interpid, 'raise Exception("it worked!")')
self.assertIsNot(exc, None)
self.assertEqual(exc.msg, 'it worked!')

Expand Down Expand Up @@ -1638,12 +1635,9 @@ def test_set___main___attrs(self):
with self.subTest('from C-API'):
with self.interpreter_from_capi() as interpid:
with self.assertRaisesRegex(InterpreterError, 'unrecognized'):
_interpreters.set___main___attrs(interpid, {'spam': True})
_interpreters.set___main___attrs(
interpid,
{'spam': True},
require_owned=False,
)
_interpreters.set___main___attrs(interpid, {'spam': True},
require_owned=True)
_interpreters.set___main___attrs(interpid, {'spam': True})
rc = _testinternalcapi.exec_interpreter(
interpid,
'assert spam is True',
Expand Down
36 changes: 18 additions & 18 deletions Modules/_xxsubinterpretersmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ interp_destroy(PyObject *self, PyObject *args, PyObject *kwds)
{
static char *kwlist[] = {"id", "require_owned", NULL};
PyObject *id;
int reqowned = 1;
int reqowned = 0;
// XXX Use "L" for id?
if (!PyArg_ParseTupleAndKeywords(args, kwds,
"O|$p:destroy", kwlist, &id, &reqowned))
Expand Down Expand Up @@ -852,7 +852,7 @@ interp_destroy(PyObject *self, PyObject *args, PyObject *kwds)
}

PyDoc_STRVAR(destroy_doc,
"destroy(id, *, require_owned=True)\n\
"destroy(id, *, require_owned=False)\n\
\n\
Destroy the identified interpreter.\n\
\n\
Expand Down Expand Up @@ -930,7 +930,7 @@ interp_set___main___attrs(PyObject *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = {"id", "updates", "require_owned", NULL};
PyObject *id, *updates;
int reqowned = 1;
int reqowned = 0;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"OO|$p:" MODULE_NAME_STR ".set___main___attrs",
kwlist, &id, &updates, &reqowned))
Expand Down Expand Up @@ -979,7 +979,7 @@ interp_set___main___attrs(PyObject *self, PyObject *args, PyObject *kwargs)
}

PyDoc_STRVAR(set___main___attrs_doc,
"set___main___attrs(id, ns, *, require_owned=True)\n\
"set___main___attrs(id, ns, *, require_owned=False)\n\
\n\
Bind the given attributes in the interpreter's __main__ module.");

Expand Down Expand Up @@ -1091,7 +1091,7 @@ interp_exec(PyObject *self, PyObject *args, PyObject *kwds)
static char *kwlist[] = {"id", "code", "shared", "require_owned", NULL};
PyObject *id, *code;
PyObject *shared = NULL;
int reqowned = 1;
int reqowned = 0;
if (!PyArg_ParseTupleAndKeywords(args, kwds,
"OO|O$p:" MODULE_NAME_STR ".exec", kwlist,
&id, &code, &shared, &reqowned))
Expand Down Expand Up @@ -1128,7 +1128,7 @@ interp_exec(PyObject *self, PyObject *args, PyObject *kwds)
}

PyDoc_STRVAR(exec_doc,
"exec(id, code, shared=None, *, require_owned=True)\n\
"exec(id, code, shared=None, *, require_owned=False)\n\
\n\
Execute the provided code in the identified interpreter.\n\
This is equivalent to running the builtin exec() under the target\n\
Expand All @@ -1152,7 +1152,7 @@ interp_call(PyObject *self, PyObject *args, PyObject *kwds)
PyObject *id, *callable;
PyObject *args_obj = NULL;
PyObject *kwargs_obj = NULL;
int reqowned = 1;
int reqowned = 0;
if (!PyArg_ParseTupleAndKeywords(args, kwds,
"OO|OO$p:" MODULE_NAME_STR ".call", kwlist,
&id, &callable, &args_obj, &kwargs_obj,
Expand Down Expand Up @@ -1192,7 +1192,7 @@ interp_call(PyObject *self, PyObject *args, PyObject *kwds)
}

PyDoc_STRVAR(call_doc,
"call(id, callable, args=None, kwargs=None, *, require_owned=True)\n\
"call(id, callable, args=None, kwargs=None, *, require_owned=False)\n\
\n\
Call the provided object in the identified interpreter.\n\
Pass the given args and kwargs, if possible.\n\
Expand All @@ -1209,7 +1209,7 @@ interp_run_string(PyObject *self, PyObject *args, PyObject *kwds)
static char *kwlist[] = {"id", "script", "shared", "require_owned", NULL};
PyObject *id, *script;
PyObject *shared = NULL;
int reqowned = 1;
int reqowned = 0;
if (!PyArg_ParseTupleAndKeywords(args, kwds,
"OU|O$p:" MODULE_NAME_STR ".run_string",
kwlist, &id, &script, &shared, &reqowned))
Expand Down Expand Up @@ -1239,7 +1239,7 @@ interp_run_string(PyObject *self, PyObject *args, PyObject *kwds)
}

PyDoc_STRVAR(run_string_doc,
"run_string(id, script, shared=None, *, require_owned=True)\n\
"run_string(id, script, shared=None, *, require_owned=False)\n\
\n\
Execute the provided string in the identified interpreter.\n\
\n\
Expand All @@ -1251,7 +1251,7 @@ interp_run_func(PyObject *self, PyObject *args, PyObject *kwds)
static char *kwlist[] = {"id", "func", "shared", "require_owned", NULL};
PyObject *id, *func;
PyObject *shared = NULL;
int reqowned = 1;
int reqowned = 0;
if (!PyArg_ParseTupleAndKeywords(args, kwds,
"OO|O$p:" MODULE_NAME_STR ".run_func",
kwlist, &id, &func, &shared, &reqowned))
Expand Down Expand Up @@ -1283,7 +1283,7 @@ interp_run_func(PyObject *self, PyObject *args, PyObject *kwds)
}

PyDoc_STRVAR(run_func_doc,
"run_func(id, func, shared=None, *, require_owned=True)\n\
"run_func(id, func, shared=None, *, require_owned=False)\n\
\n\
Execute the body of the provided function in the identified interpreter.\n\
Code objects are also supported. In both cases, closures and args\n\
Expand Down Expand Up @@ -1321,7 +1321,7 @@ interp_is_running(PyObject *self, PyObject *args, PyObject *kwds)
{
static char *kwlist[] = {"id", "require_owned", NULL};
PyObject *id;
int reqowned = 1;
int reqowned = 0;
if (!PyArg_ParseTupleAndKeywords(args, kwds,
"O|$p:is_running", kwlist,
&id, &reqowned))
Expand All @@ -1342,7 +1342,7 @@ interp_is_running(PyObject *self, PyObject *args, PyObject *kwds)
}

PyDoc_STRVAR(is_running_doc,
"is_running(id, *, require_owned=True) -> bool\n\
"is_running(id, *, require_owned=False) -> bool\n\
\n\
Return whether or not the identified interpreter is running.");

Expand All @@ -1352,7 +1352,7 @@ interp_get_config(PyObject *self, PyObject *args, PyObject *kwds)
{
static char *kwlist[] = {"id", "require_owned", NULL};
PyObject *idobj = NULL;
int reqowned = 1;
int reqowned = 0;
if (!PyArg_ParseTupleAndKeywords(args, kwds,
"O|$p:get_config", kwlist,
&idobj, &reqowned))
Expand Down Expand Up @@ -1384,7 +1384,7 @@ interp_get_config(PyObject *self, PyObject *args, PyObject *kwds)
}

PyDoc_STRVAR(get_config_doc,
"get_config(id, *, require_owned=True) -> types.SimpleNamespace\n\
"get_config(id, *, require_owned=False) -> types.SimpleNamespace\n\
\n\
Return a representation of the config used to initialize the interpreter.");

Expand Down Expand Up @@ -1446,7 +1446,7 @@ interp_incref(PyObject *self, PyObject *args, PyObject *kwds)
static char *kwlist[] = {"id", "implieslink", "require_owned", NULL};
PyObject *id;
int implieslink = 0;
int reqowned = 1;
int reqowned = 0;
if (!PyArg_ParseTupleAndKeywords(args, kwds,
"O|$pp:incref", kwlist,
&id, &implieslink, &reqowned))
Expand Down Expand Up @@ -1474,7 +1474,7 @@ interp_decref(PyObject *self, PyObject *args, PyObject *kwds)
{
static char *kwlist[] = {"id", "require_owned", NULL};
PyObject *id;
int reqowned = 1;
int reqowned = 0;
if (!PyArg_ParseTupleAndKeywords(args, kwds,
"O|$p:decref", kwlist, &id, &reqowned))
{
Expand Down
0