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
Do not expose not-ready interpreters in the high-level module.
  • Loading branch information
ericsnowcurrently committed Apr 11, 2024
commit 4f92794abde4324bdcbb2f30cf02384ae610156e
2 changes: 1 addition & 1 deletion Lib/test/support/interpreters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def create():
def list_all():
"""Return all existing interpreters."""
return [Interpreter(id, _whence=whence)
for id, whence in _interpreters.list_all()]
for id, whence in _interpreters.list_all(require_ready=True)]


def get_current():
Expand Down
40 changes: 25 additions & 15 deletions Modules/_xxsubinterpretersmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -719,29 +719,39 @@ So does an unrecognized ID.");


static PyObject *
interp_list_all(PyObject *self, PyObject *Py_UNUSED(ignored))
interp_list_all(PyObject *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = {"require_ready", NULL};
int reqready = 0;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"|$p:" MODULE_NAME_STR ".list_all",
kwlist, &reqready))
{
return NULL;
}

PyObject *ids = PyList_New(0);
if (ids == NULL) {
return NULL;
}

PyInterpreterState *interp = PyInterpreterState_Head();
while (interp != NULL) {
PyObject *item = get_summary(interp);
if (item == NULL) {
Py_DECREF(ids);
return NULL;
}
if (!reqready || _PyInterpreterState_IsReady(interp)) {
PyObject *item = get_summary(interp);
if (item == NULL) {
Py_DECREF(ids);
return NULL;
}

// insert at front of list
int res = PyList_Insert(ids, 0, item);
Py_DECREF(item);
if (res < 0) {
Py_DECREF(ids);
return NULL;
// insert at front of list
int res = PyList_Insert(ids, 0, item);
Py_DECREF(item);
if (res < 0) {
Py_DECREF(ids);
return NULL;
}
}

interp = PyInterpreterState_Next(interp);
}

Expand Down Expand Up @@ -1417,8 +1427,8 @@ static PyMethodDef module_functions[] = {
METH_VARARGS | METH_KEYWORDS, create_doc},
{"destroy", _PyCFunction_CAST(interp_destroy),
METH_VARARGS | METH_KEYWORDS, destroy_doc},
{"list_all", interp_list_all,
METH_NOARGS, list_all_doc},
{"list_all", _PyCFunction_CAST(interp_list_all),
METH_VARARGS | METH_KEYWORDS, list_all_doc},
{"get_current", interp_get_current,
METH_NOARGS, get_current_doc},
{"get_main", interp_get_main,
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy