Skip to content

[subinterpreters] Fix PyImport_Import() for subinterpreters #87717

Closed

Description

@JunyiXie
mannequin
BPO 43551
Nosy @vstinner, @junyixie
PRs
  • bpo-43551: fix PyImport_Import use static silly_list, under building Python with --with-experimental-isolated-subinterpreters share silly_list in multi sub interpreters cause crash. #24929
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2021-03-22.09:51:10.200>
    created_at = <Date 2021-03-19.07:06:36.975>
    labels = ['expert-subinterpreters', '3.10']
    title = '[subinterpreters] Fix PyImport_Import() for subinterpreters'
    updated_at = <Date 2021-03-22.10:33:18.565>
    user = 'https://github.com/JunyiXie'

    bugs.python.org fields:

    activity = <Date 2021-03-22.10:33:18.565>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-03-22.09:51:10.200>
    closer = 'vstinner'
    components = ['Subinterpreters']
    creation = <Date 2021-03-19.07:06:36.975>
    creator = 'JunyiXie'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 43551
    keywords = ['patch']
    message_count = 3.0
    messages = ['389056', '389290', '389302']
    nosy_count = 2.0
    nosy_names = ['vstinner', 'JunyiXie']
    pr_nums = ['24929']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue43551'
    versions = ['Python 3.10']

    Activity

    1. JunyiXie commented on Mar 19, 2021

      JunyiXiemannequin
      MannequinAuthor

      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);
      
      
    2. vstinner commented on Mar 22, 2021

      @vstinner
      Member

      New changeset 88d9983 by junyixie in branch 'master':
      bpo-43551: Fix PyImport_Import() for subinterpreters (GH-24929)
      88d9983

    3. changed the 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[/+] on Mar 22, 2021
    4. changed the 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[/+] on Mar 22, 2021
    5. vstinner commented on Mar 22, 2021

      @vstinner
      Member

      See bpo-43592: test_importlib: test_multiprocessing_pool_circular_import() fails with "Too many open files" error on os.pipe().

    6. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions