This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: [subinterpreters] Fix PyImport_Import() for subinterpreters
Type: Stage: resolved
Components: Subinterpreters Versions: Python 3.10
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: JunyiXie, vstinner
Priority: normal Keywords: patch

Created on 2021-03-19 07:06 by JunyiXie, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 24929 merged JunyiXie, 2021-03-19 07:08
Messages (3)
msg389056 - (view) Author: junyixie (JunyiXie) * Date: 2021-03-19 07:06
fix PyImport_Import use static silly_list under building Python with --with-experimental-isolated-subinterpreters share silly_list in multi subinterpreters  cause crash.

Under the sub interpreters parallel, PyObject_CallFunction clean stack, 
Py_DECREF(stack[i]), Py_DECREF silly_list is not thread safe. cause crash
```
PyObject *
PyImport_Import(PyObject *module_name)
{
    PyThreadState *tstate = _PyThreadState_GET();
    static PyObject *silly_list = NULL;
    ...
    /* Initialize constant string objects */
    if (silly_list == NULL) {
        import_str = PyUnicode_InternFromString("__import__");
        if (import_str == NULL)
            return NULL;
        builtins_str = PyUnicode_InternFromString("__builtins__");
        if (builtins_str == NULL)
            return NULL;
        silly_list = PyList_New(0);
        if (silly_list == NULL)
            return NULL;
    }
    ...
    /* Call the __import__ function with the proper argument list
       Always use absolute import here.
       Calling for side-effect of import. */
    r = PyObject_CallFunction(import, "OOOOi", module_name, globals,
                              globals, silly_list, 0, NULL);

```
msg389290 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-03-22 09:47
New changeset 88d9983b561cd59e5f186d98227de0c1a022b498 by junyixie in branch 'master':
bpo-43551: Fix PyImport_Import() for subinterpreters (GH-24929)
https://github.com/python/cpython/commit/88d9983b561cd59e5f186d98227de0c1a022b498
msg389302 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-03-22 10:33
See bpo-43592: test_importlib: test_multiprocessing_pool_circular_import() fails with "Too many open files" error on os.pipe().
History
Date User Action Args
2022-04-11 14:59:43adminsetgithub: 87717
2021-03-22 10:33:18vstinnersetmessages: + msg389302
2021-03-22 09:51:10vstinnersetstatus: open -> closed
versions: + Python 3.10
title: [Subinterpreters]: PyImport_Import use static silly_list under building Python with --with-experimental-isolated-subinterpreters share silly_list in multi subinterpreters cause crash. -> [subinterpreters] Fix PyImport_Import() for subinterpreters
components: + Subinterpreters
resolution: fixed
stage: patch review -> resolved
2021-03-22 09:47:19vstinnersetmessages: + msg389290
2021-03-19 07:08:23JunyiXiesetkeywords: + patch
stage: patch review
pull_requests: + pull_request23691
2021-03-19 07:06:36JunyiXiecreate