Skip to content

PathFinder is twice on sys.meta_path #77309

Closed

Description

@htgoebel
mannequin
BPO 33128
Nosy @brettcannon, @ncoghlan, @ned-deily, @ericsnowcurrently, @pablogsal, @miss-islington
PRs
  • bpo-33128 Fix duplicated call to importlib._install_external_importers  #6273
  • [3.7] bpo-33128 Fix duplicated call to importlib._install_external_importers (GH-6273) #6592
  • 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 2018-04-25.02:58:44.339>
    created_at = <Date 2018-03-23.23:30:41.727>
    labels = ['interpreter-core', '3.8', 'type-bug', '3.7']
    title = 'PathFinder is twice on sys.meta_path'
    updated_at = <Date 2018-04-25.02:58:44.338>
    user = 'https://bugs.python.org/htgoebel'

    bugs.python.org fields:

    activity = <Date 2018-04-25.02:58:44.338>
    actor = 'ncoghlan'
    assignee = 'none'
    closed = True
    closed_date = <Date 2018-04-25.02:58:44.339>
    closer = 'ncoghlan'
    components = ['Interpreter Core']
    creation = <Date 2018-03-23.23:30:41.727>
    creator = 'htgoebel'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 33128
    keywords = ['patch', '3.7regression']
    message_count = 8.0
    messages = ['314340', '314348', '314556', '314557', '314628', '315717', '315718', '315719']
    nosy_count = 7.0
    nosy_names = ['brett.cannon', 'htgoebel', 'ncoghlan', 'ned.deily', 'eric.snow', 'pablogsal', 'miss-islington']
    pr_nums = ['6273', '6592']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue33128'
    versions = ['Python 3.7', 'Python 3.8']

    Activity

    1. htgoebel commented on Mar 23, 2018

      htgoebelmannequin
      MannequinAuthor

      As of Python 3.7.0b2 _frozen_importlib_external.PathFinder exists twice on sys.meta_path, and it is the same object:

      $ python -S
      Python 3.7.0b2 (default, Mar 22 2018, 20:09:00) 
      [GCC 5.5.0] on linux
      Type "help", "copyright", "credits" or "license" for more information.
      >>> import sys
      >>> print(sys.meta_path)
      [<class '_frozen_importlib.BuiltinImporter'>,
      <class '_frozen_importlib.FrozenImporter'>,
      <class '_frozen_importlib_external.PathFinder'>,
      <class '_frozen_importlib_external.PathFinder'>]
      >>> print([id(p) for p in sys.meta_path])
      [24427944, 24430216, 24517416, 24517416]
      >>>
    2. added
      interpreter-core(Objects, Python, Grammar, and Parser dirs)
      type-bugAn unexpected behavior, bug, or error
      on Mar 23, 2018
    3. ned-deily commented on Mar 24, 2018

      @ned-deily
      Member

      Thanks for the report. git bisect result:

      1abcf67 is the first bad commit
      commit 1abcf67
      Author: Eric Snow <ericsnowcurrently@gmail.com>
      Date: Tue May 23 21:46:51 2017 -0700

      bpo-22257: Private C-API for core runtime initialization (PEP-432). (bpo-1772)
      
      (patch by Nick Coghlan)
      
    4. pablogsal commented on Mar 27, 2018

      @pablogsal
      Member

      It seems that the problem is that _Py_InitializeEx_Private calls _Py_InitializeCore and _Py_InitializeMainInterpreter. The first one calls at the end initimport that in turns calls importlib._install_external_importers that sets the PathFinder. Then, _Py_InitializeMainInterpreter calls initexternalimport that in turns calls again importlib._install_external_importers and therefore we end with two PathFinders in sys.meta_path.

      I think the solution is removing the call to initexternalimport in _Py_InitializeMainInterpreter as it has been alreade initialized by _Py_InitializeCore.

    5. pablogsal commented on Mar 27, 2018

      @pablogsal
      Member

      The same problem happens in new_interpreter as far as I understand.

    6. ncoghlan commented on Mar 29, 2018

      @ncoghlan
      Contributor

      Calling initexternalimports InitalizeMainInterpreter and from new_interpreter is right, since we only want these importers on the metapath after we know sys.path has been configured appropriately.

      It's the call from InitializeCore that's questionable, since we haven't finished setting up sys.path at that point.

    7. ncoghlan commented on Apr 25, 2018

      @ncoghlan
      Contributor

      New changeset 0977091 by Nick Coghlan (Pablo Galindo) in branch 'master':
      bpo-33128 Fix duplicated call to importlib._install_external_importers (GH-6273)
      0977091

    8. miss-islington commented on Apr 25, 2018

      @miss-islington
      Contributor

      New changeset 52a5a17 by Miss Islington (bot) in branch '3.7':
      bpo-33128 Fix duplicated call to importlib._install_external_importers (GH-6273)
      52a5a17

    9. ncoghlan commented on Apr 25, 2018

      @ncoghlan
      Contributor

      Hartmut, thanks for the issue report, and Pablo, thanks for the PR to resolve it!

    10. 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

      Labels

      3.7 (EOL)end of life3.8 (EOL)end of lifeinterpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions